Are there other ways to find shape from Shapefile?

Hello, everyone.

I want to find a certain shape from a shapefile. However, it seems that there is only one method that can meet my needs, Shape get_Shape (int ShapeIndex). Is there any other way to find Shape in a Shapefile?

For example, I can assign a key to each shape to store string data. Can I find the corresponding Shape based on the key?

Thanks.

Hello Henry.

Yes. You can use the Table.Query method, something like this (in VB):

'' set your key value
Dim key As String = "keyValue"
Dim results As Object, err As String
'' search by your key value
If sf.Table.Query("[KeyField] = """ & key & """", results, err) Then
    '' results is an array of shape indices, so if you know there is only one...
    Dim shapeIndex as Integer = results(0)
    '' then do what you need to do

Else
    '' check err value in case something went wrong
    
End If

Regards,
Jerry.

1 Like