Hi,
I created a special Feature Collection with a table which contains a Date field.
<SPAN class="comment token">//Create a feature collection and store it in a feature collection layer</SPAN>
<SPAN class="keyword token">var</SPAN> fields <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">List</SPAN><SPAN class="operator token"><</SPAN>Field<SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Field</SPAN><SPAN class="punctuation token">(</SPAN>FieldType<SPAN class="punctuation token">.</SPAN>Date<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Date"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Date"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">20</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> table <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">FeatureCollectionTable</SPAN><SPAN class="punctuation token">(</SPAN>fields<SPAN class="punctuation token">,</SPAN> GeometryType<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">,</SPAN> SpatialReferences<SPAN class="punctuation token">.</SPAN>Wgs84<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
table<SPAN class="punctuation token">.</SPAN>Renderer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">SimpleRenderer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">SimpleMarkerSymbol</SPAN><SPAN class="punctuation token">{</SPAN>Color <SPAN class="operator token">=</SPAN> Color<SPAN class="punctuation token">.</SPAN>Blue<SPAN class="punctuation token">,</SPAN> Size <SPAN class="operator token">=</SPAN> <SPAN class="number token">5</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> collection <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">FeatureCollection</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">{</SPAN>table<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> collectionLayer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">FeatureCollectionLayer</SPAN><SPAN class="punctuation token">(</SPAN>collection<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN>Id <SPAN class="operator token">=</SPAN> <SPAN class="string token">"FeatureCollectionLayer"</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> feature <SPAN class="operator token">=</SPAN> table<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateFeature</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
feature<SPAN class="punctuation token">.</SPAN>Geometry <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">MapPoint</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">11.6</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">48.1</SPAN><SPAN class="punctuation token">,</SPAN> SpatialReferences<SPAN class="punctuation token">.</SPAN>Wgs84<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
feature<SPAN class="punctuation token">.</SPAN>Attributes<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Date"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> DefaultDate<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">await</SPAN> table<SPAN class="punctuation token">.</SPAN><SPAN class="token function">AddFeatureAsync</SPAN><SPAN class="punctuation token">(</SPAN>feature<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
Map<SPAN class="punctuation token">.</SPAN>OperationalLayers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>collectionLayer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Now: When I want to Query this feature layer, I am not able to get a result match for my search date:
<SPAN class="comment token">//Now load try to query on this layer with a where clause on the date field</SPAN>
<SPAN class="keyword token">var</SPAN> layer <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>FeatureCollectionLayer<SPAN class="punctuation token">)</SPAN>Map<SPAN class="punctuation token">.</SPAN>OperationalLayers<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"FeatureCollectionLayer"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>Layers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">First</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> result <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> layer<SPAN class="punctuation token">.</SPAN>FeatureTable<SPAN class="punctuation token">.</SPAN><SPAN class="token function">QueryFeaturesAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">QueryParameters</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
WhereClause <SPAN class="operator token">=</SPAN> $<SPAN class="string token">"Date = '{DefaultDate}'"</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
layer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SelectFeatures</SPAN><SPAN class="punctuation token">(</SPAN>result<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>The result is always empty, no selection was made.
DefaultDate by the way is a static value:
<SPAN class="keyword token">public</SPAN> DateTime DefaultDate <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">get</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">set</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">DateTime</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">2019</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">05</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">08</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>In the end I used int32 instead of Date as the data type for the field and converted the date into an integer, so it finally worked.
So my questions are:
- Why does it not work with data type Date? What was wrong here?
- Why does data type Date needs a length when creating the field? What is it for? Is it used?
- I missed a data type boolean. Any reasons why it is missing?
Kind regards
Max