Check the following Python code
from arcgis.features import FeatureLayer
from arcgis.geometry import Geometry
url = 'https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/NYCDemographics1/FeatureServer/0'
layer = FeatureLayer(url)
query = layer.query(
where = '1=1',
out_sr = 4326,
geometry_precision = 6,
result_record_count = 10,
geom = Geometry(query.features.geometry)
I am trying to compute the 'label_point' property of a Polygon object in Python API (1.4)
But I get 'None'. Same goes for 'centroid' or other properties, shall I use another constructor for Geometry?
Without a GIS object instantiated, geometry operations will be attempted using locally installed geometry libraries, i.e., ArcPy or Shapely. This is what Aaron is referencing. If you don't have a local geometry library, the operations will return None (or possibly error).
If you don't want to or can't install a local geometry library, you can use the geometry service from AGOL or an ArcGIS Enterprise.
import arcgis gis = arcgis.gis.GIS() url = 'https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/NYCDemographics1/FeatureServer/0' layer = arcgis.features.FeatureLayer(url) query = layer.query( where = '1=1', out_sr = 4326, geometry_precision = 6, result_record_count = 10, ) label_points = arcgis.geometry.label_points( spatial_ref=4326, polygons=[feature.geometry for feature in query.features], gis = gis ) print (label_points)
But for 'centroid'? Only via shapely?
My usecase: I am building an API that connects to various ArcGIS REST FeatureServer services, aggregate the content, compute some geometry operations like centroids, label points then spits out GeoJSON. Before implementing all these by myself I want to check if most of these tasks are possible using 3rd party (still maintained) libraries.
Regarding ArcGIS API for Python, yes, you will need a local geometry library (ArcPy or Shapely) installed for it to work. If you are so inclined, you could retrieve the geometry as GeoJSON and then have some Python library that works on GeoJSON calculate a centroid. In effect, you could use some other package besides ArcGIS API for Python calculate the centroid of the geometry.