Skip to content

Commit 805a141

Browse files
committed
feat: derive extent from point coordinates in CreateNetworkDataset
When point features are supplied as the area of interest, compute the download bbox from actual min/max coordinates (via cursor) rather than desc.extent, which may reflect the spatial domain instead of true data extent. - Project points to WGS84 first if needed, then read SHAPE@XY via cursor - Non-point geometry types continue to use extent.projectAs(wgs84) - Expand the WGS84 bbox by ~1 mile in each direction before downloading and before building the clip polygon - Clip polygon always created in WGS84 to match the normalised extent
1 parent aa96023 commit 805a141

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

arcgis/overture_to_arcgis.pyt

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ class CreateNetworkDataset:
885885
parameterType="Required",
886886
direction="Input"
887887
)
888-
download_data.value = False
888+
download_data.value = True
889889

890890
# extent for downloading data
891891
extent = arcpy.Parameter(
@@ -997,13 +997,39 @@ class CreateNetworkDataset:
997997
desc = arcpy.Describe(extent_features)
998998
extent = desc.extent
999999
spatial_reference = desc.spatialReference
1000-
1001-
if spatial_reference.factoryCode != 4326:
1002-
logger.info("Projecting extent to WGS84 (EPSG:4326).")
1003-
projected_extent = extent.projectAs(arcpy.SpatialReference(4326))
1004-
bbox = (projected_extent.XMin, projected_extent.YMin, projected_extent.XMax, projected_extent.YMax)
1000+
is_point_input = desc.shapeType in ("Point", "Multipoint")
1001+
1002+
wgs84 = arcpy.SpatialReference(4326)
1003+
1004+
if is_point_input:
1005+
# project to WGS84 first if needed, then derive extent from actual coordinates
1006+
if spatial_reference.factoryCode != 4326:
1007+
logger.info("Projecting point features to WGS84 (EPSG:4326).")
1008+
pts_for_extent = arcpy.management.Project(extent_features, "memory/extent_points_proj", wgs84)[0]
1009+
else:
1010+
pts_for_extent = extent_features
1011+
1012+
x_coords, y_coords = [], []
1013+
with arcpy.da.SearchCursor(pts_for_extent, ["SHAPE@XY"]) as cursor:
1014+
for row in cursor:
1015+
x, y = row[0]
1016+
x_coords.append(x)
1017+
y_coords.append(y)
1018+
1019+
buffer_dist = 1609.344 / 111320.0 # approx. 1 mile in degrees
1020+
logger.info("Point features provided as area of interest; expanding extent by ~1 mile in each direction.")
1021+
extent = arcpy.Extent(
1022+
min(x_coords) - buffer_dist,
1023+
min(y_coords) - buffer_dist,
1024+
max(x_coords) + buffer_dist,
1025+
max(y_coords) + buffer_dist,
1026+
)
10051027
else:
1006-
bbox = (extent.XMin, extent.YMin, extent.XMax, extent.YMax)
1028+
if spatial_reference.factoryCode != 4326:
1029+
logger.info("Projecting extent to WGS84 (EPSG:4326).")
1030+
extent = extent.projectAs(wgs84)
1031+
1032+
bbox = (extent.XMin, extent.YMin, extent.XMax, extent.YMax)
10071033
logger.info(f"Retrieving Overture features for extent: {bbox}.")
10081034

10091035
# create temp directory and geodatabase for downloaded data
@@ -1020,9 +1046,19 @@ class CreateNetworkDataset:
10201046
connector_fc = str(Path(temp_gdb) / "connectors")
10211047
overture_to_arcgis.get_features(connector_fc, bbox=bbox, overture_type="connector")
10221048

1023-
# remove features outside the extent geometry
1024-
ext_lyr = arcpy.management.MakeFeatureLayer(extent_features)[0]
1049+
# create feature layer for extent features
1050+
logger.debug("Creating feature layer for extent features to use for spatial filtering.")
1051+
array = arcpy.Array([
1052+
arcpy.Point(extent.XMin, extent.YMin),
1053+
arcpy.Point(extent.XMin, extent.YMax),
1054+
arcpy.Point(extent.XMax, extent.YMax),
1055+
arcpy.Point(extent.XMax, extent.YMin),
1056+
arcpy.Point(extent.XMin, extent.YMin),
1057+
])
1058+
extent_polygon = arcpy.management.CopyFeatures([arcpy.Polygon(array, wgs84)], "memory/extent_polygon")[0]
1059+
ext_lyr = arcpy.management.MakeFeatureLayer(extent_polygon)[0]
10251060

1061+
# remove features outside the extent geometry
10261062
seg_lyr = arcpy.management.MakeFeatureLayer(segment_fc)[0]
10271063
arcpy.management.SelectLayerByLocation(seg_lyr, "INTERSECT", ext_lyr, selection_type="NEW_SELECTION", invert_spatial_relationship=True)
10281064
arcpy.management.DeleteFeatures(seg_lyr)

arcgis/overture_to_arcgis.pyt.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<metadata xml:lang="en"><Esri><CreaDate>20251022</CreaDate><CreaTime>11025600</CreaTime><ArcGISFormat>1.0</ArcGISFormat><SyncOnce>TRUE</SyncOnce><ModDate>20260318</ModDate><ModTime>234516</ModTime></Esri><toolbox name="overture_to_arcgis" alias="overture_to_arcgis"><arcToolboxHelpPath>c:\program files\arcgis\pro\Resources\Help\gp</arcToolboxHelpPath><toolsets/></toolbox><dataIdInfo><idCitation><resTitle>overture_to_arcgis</resTitle></idCitation><searchKeys><keyword>Overture Maps</keyword><keyword>ArcGIS Pro</keyword><keyword>transportation</keyword><keyword>network dataset</keyword><keyword>geoprocessing</keyword></searchKeys><idAbs>Python Toolbox for downloading, processing, and analysing Overture Maps data in ArcGIS Pro. Includes tools for retrieving Overture features, parsing complex JSON fields into usable attribute columns, splitting segments by subclass and level rules, splitting segments at connector points, and building walk-optimised network datasets.</idAbs></dataIdInfo><distInfo><distributor><distorFormat><formatName>ArcToolbox Toolbox</formatName></distorFormat></distributor></distInfo></metadata>
2+
<metadata xml:lang="en"><Esri><CreaDate>20251022</CreaDate><CreaTime>11025600</CreaTime><ArcGISFormat>1.0</ArcGISFormat><SyncOnce>TRUE</SyncOnce><ModDate>20260319</ModDate><ModTime>094824</ModTime></Esri><toolbox name="overture_to_arcgis" alias="overture_to_arcgis"><arcToolboxHelpPath>c:\program files\arcgis\pro\Resources\Help\gp</arcToolboxHelpPath><toolsets/></toolbox><dataIdInfo><idCitation><resTitle>overture_to_arcgis</resTitle></idCitation><searchKeys><keyword>Overture Maps</keyword><keyword>ArcGIS Pro</keyword><keyword>transportation</keyword><keyword>network dataset</keyword><keyword>geoprocessing</keyword></searchKeys><idAbs>Python Toolbox for downloading, processing, and analysing Overture Maps data in ArcGIS Pro. Includes tools for retrieving Overture features, parsing complex JSON fields into usable attribute columns, splitting segments by subclass and level rules, splitting segments at connector points, and building walk-optimised network datasets.</idAbs></dataIdInfo><distInfo><distributor><distorFormat><formatName>ArcToolbox Toolbox</formatName></distorFormat></distributor></distInfo></metadata>

0 commit comments

Comments
 (0)