POST
|
This is great, thanks Joshua. I'll dive into your blog post and check out these other methods. I appreciate you taking the time to explain this so clearly. In this case, since I'm reading/breaking down existing geometry objects, what would be your workflow here? The below line in my code is returning an array that represents the individual part of the multipart geometry (as expected): for i, part in enumerate(geom, start=1): I'm curious where you would go from here. As in my updated posting, doing the following works to retain the holes (nesting the "part" Array into another Array, then converting back a Polygon with the standard constructor): # Works:
exploded_polygon = ap.Polygon(ap.Array(part))
# Does not work, holes are not retained.
exploded_polygon = ap.Polygon(part) Is there a better method, where I take that existing "part" Array and handle it only with JSON? I guess I'm not sure how to get an existing arcpy.Array() into a format that can be used by either "AsShape" or "FromWKT." This is mostly an educational exercise at this point, since my update works, but I would definitely like to learn about more reliable methods of handling geometries. Thanks for your time!
... View more
06-08-2021
09:21 AM
|
0
|
0
|
3020
|
POST
|
In case someone else has a similar issue in the future: The solution to this was to nest the geometry "part" (which is already an Array) into another Array. Following this, the script works as expected. Full function below: def FeatureToPoint(in_fc, out_fc, point_location='CENTROID', explode=False):
"""
Creates a new feature class of points from input polygons or polylines.
:point_location:
CENTROID- The true centroid if it is within or on the feature;
otherwise, the label point is returned.
TRUE_CENTROID- The center of gravity for a feature.
LABEL- The labelPoint is always located within or on a feature.
:explode: create center point for each part? or just each feature?
"""
import arcpy as ap
import os
from arcpy.da import SearchCursor, InsertCursor
crs = ap.da.Describe(in_fc)['spatialReference']
ap.management.CreateFeatureclass(
out_path=os.path.dirname(out_fc),
out_name=os.path.basename(out_fc),
geometry_type='POINT',
template=in_fc,
has_m='', has_z='',
spatial_reference=crs)
flds = [f.name for f in ap.ListFields(in_fc)
if f.type not in ['Geometry', 'OID']
and f.name not in ['Shape_Area', 'Shape_Length']]
flds.insert(0, 'SHAPE@')
center_type = {'CENTROID': 'centroid',
'TRUE_CENTROID': 'trueCentroid',
'LABEL': 'labelPoint',}
with SearchCursor(in_fc, flds) as scurs, InsertCursor(out_fc, flds) as icurs:
for geom, *fields in scurs:
if explode:
for i, part in enumerate(geom, start=1):
"""
'part' is already an Array. Not clear why it needs
to be nested into another Array, but it does. Otherwise, only
the exterior ring of the part gets converted to a polygon,
excluding any internal rings.
"""
exploded_polygon = ap.Polygon(ap.Array(part))
# Testing/visualizing outputs:
#ap.management.CopyFeatures(exploded_polygon, fr'memory\Part{i}')
point_geom = getattr(exploded_polygon, center_type[point_location])
icurs.insertRow([point_geom, *fields])
else:
point_geom = getattr(geom, center_type[point_location])
icurs.insertRow([point_geom, *fields])
return out_fc
... View more
06-07-2021
07:08 AM
|
1
|
2
|
3040
|
POST
|
Thanks for the input Dan. I'm still a bit confused about this situation, however. I am (in theory, anyway) familiar with the way that ArcPy deals with geometry objects--the rings, and the Null points as separators. When I add the following print statement, I am getting the exterior rings, followed by the interior rings, all separated by the null points: (the first two lines are in the original post, and are just shown here for context) for geom, *fields in scurs:
for i, part in enumerate(geom, start=1):
print([array for array in part]) <---------LINE ADDED I won't paste in what it prints (because it's long), but an example is basically: [point, point, point, None, point, point, point, None, point, point, point] --> which is exterior ring, interior ring, interior ring. This describes that middle polygon shown in the image with the two holes. Based on this, the "part" variable contains all the rings that are necessary to create a polygon. So then why does my line below not create this polygon object, with these interior rings intact?: arcpy.management.CopyFeatures(arcpy.Polygon(part), fr'memory\Part{i}') You said, "when it is read, only the exterior ring is read." I don't follow what you mean here--if I was trying to get the .boundary() or something, that would make sense to me. But since the exterior and the interior rings are contained in the "part" object (evidenced by the print statement), why can't "part" be used to construct a Polygon object? The arcpy.Polygon() class doesn't read interior rings in this case? Would you be able to provide some code that would convert a polygon's part into a separate polygon? In regard to the difference between 'centroid', 'trueCentroid', and 'labelPoint'--my code here is part of a larger script that allows the user to supply any of these. The above snippet is just an example to make it easier for folks to help me solve this issue. For now, the centroid is sort of a moot point, it's really the polygon situation that I would like to understand. And as for MultipartToSinglepart--my goal is to learn about the inner workings of geometries, and why this isn't working the way I would expect it to. But you're right, I'll probably just revert to that once I (hopefully) learn why this approach is wrong. Thanks again for all your help.
... View more
06-06-2021
06:20 PM
|
0
|
0
|
3046
|
POST
|
I am attempting to generate a center point for each part of a multipart geometry. The issue I am having is that when reading multipart geometries (some with holes), the internal rings are not retained when reading/writing the individual parts. For testing, I am copying each part to a memory feature class (see images where holes are ignored). Because of this, the "labelPoint" property is not working as I would like it to. I am aware that I can use MultipartToSinglePart first, but I'd prefer to understand what part of this I'm not doing correctly, and handle the whole thing using Cursors. # IMPORTS------------------------------------------------------------------#
import arcpy
import os
from arcpy.da import InsertCursor, SearchCursor
# INPUTS-------------------------------------------------------------------#
in_fc = r'E:\SCRATCH.gdb\_MULTIPART_POLY'
out_fc = r'E:\SCRATCH.gdb\_CENTROID'
# MAIN---------------------------------------------------------------------#
# Create new output feature class.
arcpy.management.CreateFeatureclass(
out_path=os.path.dirname(out_fc),
out_name=os.path.basename(out_fc),
geometry_type='POINT',
template=in_fc,
spatial_reference=2248)
# Get relevant fields from the input FC to transfer. Add SHAPE@ token.
flds = [f.name for f in ap.ListFields(in_fc)
if f.type not in ['Geometry', 'OID']
and f.name not in ['Shape_Area', 'Shape_Length']]
flds.insert(0, 'SHAPE@')
# Read geometries, write centroids. Make TEMP copies of each geometry part.
with SearchCursor(in_fc, flds) as scurs, InsertCursor(out_fc, flds) as icurs:
for geom, *fields in scurs:
for i, part in enumerate(geom, start=1):
arcpy.management.CopyFeatures(arcpy.Polygon(part), fr'memory\Part{i}')
point_geom = getattr(arcpy.Polygon(part), 'labelPoint')
icurs.insertRow([point_geom, *fields]) The input polygon (one, multipart feature), followed by the output polygon parts and corresponding points: Input polygons. Separate output polygons, and corresponding label points.
... View more
06-05-2021
08:48 PM
|
0
|
5
|
3107
|
POST
|
I have field teams that frequently need to take map areas offline while using Field Maps to collect data. I have found that once a map is set up to be taken offline, the hosted feature layers within that are editable are converted to WGS84--meaning, after the collected field data is synced, and then exported to a File Geodatabase, the spatial reference for this data will be WGS84. To be clear, these layers were originally published in our State Plane coordinate system (except the basemap, that's WGS84), and I do not have this same experience when using live syncing (NOT taking the maps offline). In cases where cell service is decent, and we don't need to set up maps as offline capable, the exported feature layers seems to maintain the original State Plane coordinate system that they started with when published. Can anyone confirm that this is expected behavior, and/or if there is a workaround? My guess as to what is happening is that an offline device cannot manage complex coordinate system transformations on the fly, so everything is transformed into Web Mercator once a map is "offline enabled."
... View more
05-04-2021
06:28 AM
|
1
|
4
|
1384
|
POST
|
Eric, Did you ever get a resolution to this issue? I am finding something similar when taking photos using Survey123 on an iPad--regardless of orientation, the EXIF orientation tag is logged as 1.
... View more
04-29-2021
02:45 PM
|
0
|
0
|
1564
|
POST
|
Thanks for the quick reply Aaron. Fantastic, thanks, this has helped me get this to work in both Map Viewer and in the online interface for Field Maps. After a mobile reload, everything shows as expected. Some screenshots for posterity. This is within Map Viewer.
... View more
04-23-2021
06:57 AM
|
1
|
0
|
7449
|
POST
|
I am unable to view all fields within a hosted feature layer when using the Field Maps app. These are fields that I have added after the initial push to an ArcGIS Online map, and after pulling this map up once in Field Maps (on mobile) to make sure it shows. I added one additional field through Pro, one through Map Viewer (the new version), and one using the Data tab for the hosted feature layer. In all three of the above places, I can then see these three additional fields. However they will not show up in Field Maps. Is there some way to toggle what fields display within the Field Maps app? Or refresh what shows somehow? Thanks in advance.
... View more
04-22-2021
10:02 PM
|
0
|
7
|
7498
|
POST
|
I don't think this is the best way to create smooth, aesthetically pleasing contours. I have found the best approach is smooth the source data, rather than the contours lines. Try using Focal Statistics on your DEM (which I assume you have access to, since you referenced lidar) first, and THEN running contours.
... View more
11-25-2020
11:56 AM
|
0
|
0
|
2360
|
POST
|
Definitely a workaround, but I wish we didn't have to do this every time. It seems like deleting and recreating the legend will fix the issue (at least sometimes?), but I can't tell what triggers it to happen in the first place or what triggers it again after creating a new legend. Seems like a fresh, new bug for Pro; I don't recall dealing with legend issues as much in ArcMap, even if the GUI was a little confusing.
... View more
10-26-2020
07:00 PM
|
0
|
0
|
1506
|
POST
|
Thanks for the reply Tom Bole. I'd really appreciate you passing this along to the Layout team. Please let me know if this is something that gets logged. At the very least, it's frustrating that a legend will hop around when adjusting small formatting settings, and at worst, "Only show features visible in the map extent" is entirely unusable while generating a Map Series.
... View more
08-31-2020
05:38 AM
|
0
|
0
|
3139
|
POST
|
Thanks Dan, this is what I suspected. I don't mind "Project" doing this, as the user should probably know what they're getting into if they go to use that tool. Turning on the warning flag in Pro is sort of a start, but I believe the message is something like "Don't worry, we applied a transformation for you!" which is not helpful when the software inherently applies a sub-par transformation. In ArcGIS Desktop, it would raise a flag and NOT fix the issue, forcing the user to sort it out. Off to the ArcGIS Ideas board. Thanks again!
... View more
08-06-2020
07:16 AM
|
0
|
0
|
1118
|
POST
|
I'd prefer ArcGIS Pro not decide what transformations are best to apply, and would like to receive the same warning that I did in ArcGIS Desktop when adding data of different coordinate reference systems. Is there a setting somewhere to turn off the automatic application of the first transformation from Esri's dropdown list. I'd prefer to force the user to manually go in and set one. It appears possible to toggle a warning message that a transformation has been automatically applied, but not prevent the transformation from being applied in the first place. This is particularly relevant when transforming between various realizations of NAD83 within a specific state, where the first choice is often a generalized transformation involving WGS84, versus a state-specific grid-method that is superior.
... View more
08-05-2020
05:36 PM
|
0
|
2
|
1168
|
POST
|
Nicholas, Thanks for sharing these workarounds/fixes and the your observations. I had the same experience when printing the workspace to verify it hadn't been "unset." At this point, I've opted to always use my own workspace variable for outputs, or alternatively, use EnvManager, which seems to fix the issue (although is even more cumbersome than using full paths when dealing with lots of outputs).
... View more
07-15-2020
03:30 PM
|
1
|
0
|
2509
|
POST
|
Joshua, Thanks a ton for this helpful information, glad to hear the issue is likely not just bad syntax on my end. Since this snippet part of a larger tool that is destined for a toolbox anyway, hopefully it will be a nonissue in that context. Worst case, I'll go with the add/remove strategy. Thanks again.
... View more
07-08-2020
10:46 AM
|
0
|
0
|
1692
|
Title | Kudos | Posted |
---|---|---|
1 | 07-07-2020 01:01 PM | |
1 | 10-09-2024 07:22 AM | |
1 | 07-17-2024 02:57 PM | |
1 | 10-24-2024 07:51 AM | |
1 | 04-23-2021 06:57 AM |
Online Status |
Offline
|
Date Last Visited |
a month ago
|