Hello
Could you try to add a shape file layer with only one column in it and then do:
Feature f = FeatureLayer.FeatureSource.GetFeatureById(id, ReturningColumnsType.AllColumns);
I'm getting index out of bounds exception.
Hello
Could you try to add a shape file layer with only one column in it and then do:
Feature f = FeatureLayer.FeatureSource.GetFeatureById(id, ReturningColumnsType.AllColumns);
I'm getting index out of bounds exception.
Hi Rui,
The index is start from 1 to the features' count. You could get the features' count by using the method FeatureLayer.FeatureSource.GetCount(). Please make sure that the id you passed is between 1 to the features' count. If you still have problem please let me know.
Thanks,
Johnny
Rui,
Can you verify that the issue is the Id you are passing or the number of columns?
David
Rui,
Also if you could include the entire error message that would help as well.
David
Rui,
I did a simple test with only one column and try to get the specified feature by id, all works fine. Please check if there is any difference with yours. It seems that the “Index out of range” exception comes from the error feature id, such as zero or bigger than the count of features in FeatureSource, could you have a check?
Thanks,
Johnny
TestData.zip (8.5 KB)
LoadAShapeFileWithOneColumn.zip (1.86 KB)
Hello, thanks to all.
Please correct if i'm wrong, but i think i found the issue origin.
In a ShapeFileLayer if i do GetFeatureById, is "the index" that is searched, not the column Id.
When is SQLSrv2008 is the primarykey column that is searched, since is at the same time the index.
So in my case i should do QueryTools.GetFeaturesByColumnValue.
This is it, right?!
Rui,
I am not sure what you mean. Maybe we should step back and ask a more simple question. What kind of data do you have and what do you want to accomplish? In the first post you mentioned shape files and not you mention SQL 2008. We should just start with what you are trying to accomplish. Any sample code you can provide would be great.
David
David, i want both.
but let's see first ShapeFile.
if i have a shp with the following:
id |
1 |
3 |
when i do a FeatureLayer.FeatureSource.GetFeatureById(3), it will give index out of bound, because the id of the shapes are from the idx it has nothing to do with being the column id.
It's fine, i was not seeing the things right before the first post. I wasn't understandig the full FeatureLayer.FeatureSource.GetFeatureById meaning. now i do, and i think it's fine.
You may close the thread.
Rui,
Sorry for the confusion. With shape files the Id is usually the record number which is the record position. You are correct it is not the Id column in the dbf file. :-)
In other source like MS SQL Server, Oracle, etc the Id is the primary key. They are a bit different than shape files. One thing to consider is that is you use the GetFeatureById in MS SQL, Oracle, or other spatial databases then each time you call that it will execute a SQL statement. I say this to let you know if you call the GetFeatureById in a loop it could be slow.
If you have any more questions please do not hesitate to ask.
David