Part 2... Deconstructing Geometry
---- On to the examples ----
The polygons that I will be using are shown to the right.
Each part is labelled at the labelpoint rather than the centroid, hence each part gets labelled.
I will be omitting examples that rely on json representation or the __geo_interface__ method since they don't add much to the functionality of constructing and deconstructing poly* type features.
---- Getting Geometry from FeatureClasses ---- |
---|
---- The SearchCursor Approach ----The functions getSR and _view_ are described at the end. They are helper functions used to derive the spatial reference and to reshape the coordinates. The key operative in this approach is on line 8, _as_narray, which does the conversion behind the scenes.
---- Results .... Essentially you have a simplified list of X, Y coordinates since the 'shp' was defined as 'SHAPE@X' and 'SHAPE@Y' with 'explode_to_points' set to True (False, returns centroids). Sadly you can't reconstruct the polygons unless you deal with the which points belong to what polygon.
|
---- The FeatureClassToNumPyArray Approach ----This produces the same results above, requires the same sort of inputs. Timing shows that they are strongly related, especially since _as_narray has a fields and dtype property.
|
---- Retrieving shape objects ----If you want to use arcpy directly because of the builtin methods, you need the contents of the 'shape' fields using SHAPE@' rather than just extracting the X and Y coordinates as in the previous example
---- Put it to work ----
|
---- Geometry as a structured array ----Nothing fancy, but there is an integer ID field indicating which feature a point belongs to and the coordinates. A simpler version of the above... just an ID field and coordinates.
---- The results ----
The polygon ID that each point belongs to is retained, however, it is replicated many times and the null points separating polygon parts is removed. |
--------------------------------------------------------------------------
_view_ .... view structured arrays as an unstructured array |
---|
_getSR .... spatial reference for a featureclass |
|
Result...
|
getSR ....
Which you can use for basic spatial reference facts ( dir(SR) for a full list )
|
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.