ThinkGeo.com    |     Documentation    |     Premium Support

ExecuteQuery not returning correct values?

I’ve been messing with the ExecuteQuery function and I don’t seem to be getting correct values returned.

For example, I have a shapefilefeaturelayer named earthquakes and I try to perform the following query on it using the below:

string CommandText = "Select * from earthquakes where LOCATION LIKE ('n%')";

DataTable features = (SelectedLayer as ShapeFileFeatureLayer).QueryTools.ExecuteQuery(CommandText);

This should return all of the features that have a location attribute starting with ‘n’, which is multiples. But only one is returned.

earthquakes.zip (319.6 KB)

I’ve attached the shapefile above.

Edit: Another query not returning the correct stuff I found is:

"Select * from earthquakes where OBJECTID <> 1"

Instead of returning all the features where objectid != 1, it returns the first feature that has objectid = 1, and returns the rest except the very last feature. I’ve tested with various values and get the same result.

Also,

"Select * from earthquakes where OBJECTID >= 5400"

returns the first 25 features, which all have OBJECTID < 5400, instead of features where the OBJECTID is >= 5400.

Hi Dan,

I tested your data, it looks everything goes well, please view my screen shots about it.

Regards,

Ethan

Thanks for checking out the data. That’s strange, I have the same setup. I’ll check the SQL command text again tomorrow. One semi-related question. All the column data shows up as exponential notation for some reason. Like in your first screenshot, for the month, day, hour, minute, etc. columns, the data shows as -9999 as it should. On mine, it shows up as -9.0000E+some number. Any idea what might be causing this? Thanks!

Hi Dan,

  1. You need use (‘N%’) instead of (‘n%’), I found it looks the statement is case sensitive.

  2. You need to use GeoDataTable instead of DataTable.

  3. Please make sure update all your package to the latest version.

And I am not sure why your -9999 shows like -9.0000E+x, I guess that’s related with your IDE environment, you can try to save it to file and view it in other utility to make sure it.

Regards,

Ethan

Here’s what I found after messing around a bit:

When retrieving all features into a Collection, the data shows up as the scientific notation. When retrieving them into a GeoDataTable, the correct format shows up. Could this be a bug on ThinkGeo’s end?

Also, is there a way to convert a GeoDataTable back into features? The whole reason I’m doing this is that I want to query out a subset of features to create a new layer. The user wanted an SQL query-like system in place, which the executeQuery() seems to work great for. I just don’t see an easy way to turn the GeoDataTable that is returned back into features/a layer.

Thanks!

Edit:

Get a subset of shape file features based on field values this is my issue

Hi Dan,

I don’t know how you assign it to Collection because the return type is GeoDataTable.

You should want to write a custom function, loop the GeoDataTable and convert it to the target type you want, for example collection or a group of feature.

And I want to let you know that the ExecuteQuery get result from Tab file but not Shp file, so you cannot get the feature directly from the result, you need to find the corresponding feature by specified value.

Regards,

Ethan

I mean if I do FeatureSource.GetFeaturesByColumnValue, or GetAllFeatures, anything like that returns a collection of features with the data shown in scientific notation.

What is the Tab file?

I don’t think it’s possible to loop over the GeoDataTable and make features from it, because not enough info about the features are returned to the table. For instance, if I have a layer with two features in it. Both features have one column called “Location”, and a value of “US”. But the spot on the actual map where those features are isn’t returned to the GeoDataTable, and I have no way of comparing column values since they are the same.

If the ExecuteQuery() could return the IDs of the features, then I could save those and used the GetFeatureByID() function.

Is there a way to pull out the geometry as well as the attributes?

Hi Dan,

The shape file have a group of files, the tab file can be viewed by some utility for example Excel, it only contains the additional information which will be found in our Feature.ColumnValues, and the shp file contains the shape, they are separated.

It looks your data contains a column named “OBJECTID”, and we have a API named QueryTools.GetFeaturesByColumnValue, I think you can query and get a GeoDataTable at first, then loop the rows of it and query the feature by the API GetFeaturesByColumnValue.

Wish that’s helpful.

Regards,

Ethan