POST
|
I am working in a jupyter notebook, trying to query a SQL database via pyodbc and turn the output data into a spatially enabled dataframe. I can successfully read my SQL query as a regular pandas dataframe, including a column with the geometry as WKT. Can one manually add a SHAPE column (of properly converted geometry WKT into Geometry objects) to an existing pandas dataframe to create a spatially enabled dataframe? Another way to phrase this would be, can one create a spatially enabled dataframe starting with geometry as WKT? I'm working with polygon data, so from_xy() would not work. A similar question posed in 2018 suggests not without some clunky workarounds via outside libraries (shapely, geojson).
... View more
08-26-2020
08:57 AM
|
1
|
0
|
636
|
POST
|
I have a layer of polygons and would like to be able to plot the extent boundary rectangle on a map. I have my polygons in a Spatially Enabled DataFrame (polygonSDF = poygonFeatureSet.sdf) that I can successfully plot using spatial.plot(). I've so far tried two different potential approaches to this problem and in both cases have run into errors I haven't been able to solve. I don't want to use draw() as described in the Spatially Enabled DataFrames Advanced Topics tutorial because then you lose the attribute information of the original polygon, and just have a static graphic. Can anyone either point out a fix to one of the approaches described below, or suggest an alternate way to solve this problem? I'm working with ArcGIS API for Python 1.6.1 in the ArcGIS 10.7.1 Jupyter Notebook set-up on Windows 10. I'm calculating and storing the extent data as follows: extentList = []
for f in polygonFeatureSet.features:
# Calculate the extent
(w, s, e, n) = Geometry(f.geometry).geoextent
extent = Polygon({
"rings" : [[[e, s],[w, s],[w, n],[e, n], [e, s]]],
"spatialReference" : {"wkid" : 4326} })
# Add the extent to extentList
extentList.append(extent)
# Add the extents to the dataframe as a new column
polygonSDF["MBRextent"] = extentList Approach 1: Specify which column of geometry plot() uses Issue: plot() doesn't appear to have this functionality, and just uses SHAPE automatically Approach 2: Make a copy of my polygon SEDF, and then set the SHAPE column to store the extent data instead Issue: Despite extentList containing valid Geometry objects, once loaded into the SEDF the MBRextent column is of type 'object', and thus is unable to be recognized and used as geometry. # Attempt 1
copySDF['SHAPE'] = copySDF['MBRextent']
# Attempt 1 Error
AttributeError: Cannot use 'geom' accessor on objects of dtype 'object'.
# Attempt 2
copySDF.set_geometry(['MBRextent'])
# Attempt 2 Error
TypeError: Input geometry column must contain valid geometry objects.
# Attempt 3
extentDF = pd.DataFrame(polygonSDF["MBRextent"]).set_geometry(["MBRextent"])
# Attempt 3 Error
TypeError: Input geometry column must contain valid geometry objects. Approach 2B: To try to rectify the issues caused by the extent being of type 'object' I've tried explicitly setting the column type to Geometry. Issue: Geometry type is not being recognized by pandas methods # Attempt 1 - replacement of Line 12 when creating the extent column
polygonSDF["MBRextent"] = pd.Series(extentList, dtype=Polygon)
# Attempt 1 error
TypeError: dtype '<class 'arcgis.geometry._types.Geometry'>' not understood
# Attempt 2 - setting type after creation of extent column
polygonSDF['MBRextent'].astype(Geometry)
# Attempt 2 error
TypeError: dtype '<class 'arcgis.geometry._types.Geometry'>' not understood
# Attempt 3 - setting type after creation of extent column
polygonSDF["MBRextent"].astype(polygonSDF['SHAPE'].dtype)
# Attempt 3 error
NotImplementedError:
... View more
08-13-2020
08:53 AM
|
0
|
0
|
1078
|
POST
|
I am working with the ArcGIS API for Python mapping widget within the ArcGIS jupyter notebook environment. I've successfully connected to my organization's enterprise portal, grabbed content, mapped it, and set the zoom level manually (see code below). The problem is when I try to zoom to the added layer, at which point I receive the error: AttributeError: 'MapView' object has no attribute 'zoom_to_layer' According to the arcgis.widgets documentation page and all other Esri tutorials I've seen zoom_to_layer() exists and I'm using the correct syntax, of "map.zoom_to_layer(layer)". The only thing I can think of is that since my installation of the API is what comes with ArcGIS 10.7.1 (API version 1.6.1) whereas all the online API documentation pages are for version 1.8.2. Is zoom_to_layer() functionality that has been implemented between those two versions? Or can anyone else think of reasons why this might be erroring? gis = GIS("portal_url", username="my_username") contentItem = gis.content.get('content_string') contentLayer = contentItem.layers[0] m = gis.map() m.add_layer(contentLayer) m.zoom_to_layer(contentLayer) #this errors # m.zoom = 14 #this works fine m
... View more
08-10-2020
06:28 AM
|
0
|
3
|
1154
|
Title | Kudos | Posted |
---|---|---|
1 | 08-26-2020 08:57 AM |
Online Status |
Offline
|
Date Last Visited |
05-17-2021
11:48 AM
|