Closed MadGeologist closed 5 months ago
Thank you for the report! I was actually just investigating an issue similar to this last week which (frustratingly) resolved itself on its own.
"It's great to see examples of these features tested out on the square state of Colorado at the User Summit..."
🤣 I'll have you know that I have never tested on Colorado. I prefer the historic and curvy Guerry dataset.
I think this is not necessarily an issue with {arcgis} but might be an issue with the webviewer and the json that is being generated. Every request succeeds.
We can see that the featurecollection json is available and viewable
The json is a published item:
BUT when I read the item back into memory, that location and a few others seems corrupted. I think this is an issue specifically with MultiPolygons
The json of the one item that sucks is breaking things
I appreciate you taking the time to make a reproducible issues. Its impossible for me to single handedly know and anticipate all of the places that issues may occur.
Thanks for the lightning-fast response and you're absolutely correct, products like these are a huge undertaking - it's impossible to see everything caveat, and I would've 1000% failed if I had to make this tool myself - so thanks for a bunch for the work you do! I'll stop being an angry geologist haha.
After doing some digging I can concur that the regions that failed to load where in part to nested polygons.
^^ is an example of a region where it imploded
^^ is an example of a region where it draws properly
I wonder if there's a way to un-nest the jsons/make them into a singular list (I have no idea what I'm talking about)
I wonder if there's a way to un-nest the jsons/make them into a singular list (I have no idea what I'm talking about)
you're not actually far off! Theoretically we could use sf::st_cast(geometry)
to expand them into multiple. But then we lose the fact that each feature is one row!
the esriGeometryPolygon
object, as far as I can tell does not support multiple polygons
{
"hasZ": <true | false>,
"hasM": <true | false>,
"rings": [
[
[<x11>, <y11>, <z11>, <m11>],
[<x1N>, <y1N>, <z1N>, <m1N>]
],
[
[<xk1>, <yk1>, <zk1>, <mk1>],
[<xkM>, <ykM>, <zkM>, <mkM>]
]
],
"spatialReference": {<spatialReference>}
}
I've reached out to some internal resources to see what i can find out!
Hmm interesting, I might try a few things to see if there's a way to keep track of the original row when "de-listing" or "combining" the rings.
Thanks for reaching out to internal support, one interesting thing that I've noticed is that the arcgis api for python (versions 2.0 >) found a workaround for multi-polygons as I've been able to upload those without facing artifact issues.
Here's an example in case this reference is of any help:
### Libraries and installation
##############################
import arcgis
import numpy as np
import os
import pandas as pd
from pandas import json_normalize
import json
#import shapefile
from arcgis import GIS
import arcgis
import geopandas as gpd
from geopandas import GeoSeries, GeoDataFrame
from arcgis.features import FeatureCollection,FeatureLayer,FeatureSet
from arcgis.features import GeoAccessor, GeoSeriesAccessor,FeatureLayerCollection
### Login to AGOL
###################
# Set up keybase enviornment
ENV_SCOPE = os.getenv("p_env_secretscope_name")
# Extract the username and password
un = dbutils.secrets.get(scope=ENV_SCOPE, key="sec-ago-headless-username")
pw = dbutils.secrets.get(scope=ENV_SCOPE, key="sec-ago-headless-password")
# Login
gis = GIS("https://fema.maps.arcgis.com",
username = un,
password = pw
)
print("Logged into AGOL")
# Pull down the CCRI Counties:
CCRI_Counties = gis.content.get(itemid ="ff17676850114091b28cb4c502e9fb4e")
CCRI_Counties_Layer = CCRI_Counties.layers[0].query(where = "STATEFP = '36'")
# Processs the data, convert to geojson
CCRI_Counties_string = CCRI_Counties_Layer.to_geojson
CCRI_Counties_gsjon_dict = json.loads(CCRI_Counties_string)
print("Converted Item to JSON")
# Convert the geojson to dataframe
CCRI_Counties_gdf = gpd.GeoDataFrame.from_features(CCRI_Counties_gsjon_dict['features'])
CCRI_Counties_gdf = gpd.GeoDataFrame(CCRI_Counties_gdf, geometry='geometry')
CCRI_Counties_gdf = CCRI_Counties_gdf.set_crs(epsg=3857, inplace=False,allow_override=True)
CCRI_Counties_gdf = CCRI_Counties_gdf.to_crs(epsg=4326)
# Cast projection
CCRI_Counties_gdf = CCRI_Counties_gdf.to_crs(epsg=4263)
# Convert into a spatially enabled data frame
**CCRI_Counties_SDF = GeoAccessor.from_geodataframe(CCRI_Counties_gdf,column_name ="geometry")**
# Cast the projection
CCRI_Counties_SDF.spatial.set_geometry(col="geometry",sr="4263",inplace=True)
# Send to arcgis online
**CCRI_Counties_SDF.spatial.to_featurelayer('Gitlab Demonstration - Delete Later')**
Gets them nested geometries in with no problem:
It looks like the answer is inside the 'to_featurelayer()' function it must be doing some translation to work with the glitchy webview json haha or maybe converting the geopandas into a spatially enabled dataframe (is there a R equivalent?) - having this work in R would be awesome for our team as we have an easier time automating tasks in R (long story).
@MadGeologist would you be able to share the json from the SEDF for the feature that is causing us problems?
Sure thing, here's the JSON from the SEDF that was sent up into the AGOL platform. SpatiallEnabledDataFrameExample.json
Let me know if this link works!
I hope all is well, any updates on the fate of this? :)
@MadGeologist i have not forgotten, I swear! I'm going to try to poke some more trees internally and do some personal exploration with our other sdks and see how they handle OGC multipolygons.
So I don't have to find it again. The polygon with multiple rings can be queried here
There is a bug in the multipolygon conversion. There should be 8 rings
library(arcgis)
#> Attaching core arcgis packages:
#> → arcgisutils v0.2.0.9000
#> → arcgislayers v0.2.0
furl <- "https://services.arcgis.com/XG15cJAlne2vxtgt/arcgis/rest/services/Counties_FEMA_Community_Resilience_Challenges_Index_(CRCI)/FeatureServer/54"
arc_read(furl, where = "objectid = 86", fields = "objectid") |>
as_esri_featureset() |> jsonify::pretty_json()
#> {
#> "geometryType": "esriGeometryPolygon",
#> "spatialReference": {
#> "wkid": 3857
#> },
#> "hasZ": false,
#> "hasM": false,
#> "features": [
#> {
#> "attributes": {
#> "OBJECTID": 86
#> },
#> "geometry": {
#> "rings": [
#> [
#> [
#> -8237586.37457029,
#> 4968241.45045267
#> ],
#> [
#> -8237364.18085601,
#> 4968142.19106731
#> ],
#> [
#> -8237647.42813149,
#> 4968114.62567107
#> ],
#> [
#> -8237586.37457029,
#> 4968241.45045267
#> ]
#> ]
#> ]
#> }
#> }
#> ]
#> }
@MadGeologist by golly, we got it!
I'll push the change to {arcgisutils}
shortly.
Would you mind installing the packages again via?
pak::pak("r-arcgis/arcgisutils")
pak::pak("r-arcgis/arcgislayers")
My Man! looks like it works, thanks so much!
Note that this is being entirely rewritten in Rust and should be more reliable. The fix that is referenced in this PR led to more issues. So, by the next week and next release of arcgisutils the bug will be fixed—ideally, permanently and will support 3D geometries as well.
Hi, so I have an issue where complex geometries fail to draw when they are uploaded to AGOL using the
publish_layer()
feature. It appears that complex geometries have a significant difficulty loading when published to arcgis online.Here is an example with some code that demonstrates this glaring issue in R while trying to pull down a public dataset involving CCRI:
`### Login to AGOL token_AGOL <- auth_user( username = "U", password = "PW", host = arc_host(), expiration = 21600 ) set_arc_token(token_AGOL)
Pull Down CCRI
CCRI_URL = "https://services.arcgis.com/XG15cJAlne2vxtgt/arcgis/rest/services/Counties_FEMA_Community_Resilience_Challenges_Index_(CRCI)/FeatureServer/54"
Open Layer
CCRI_Layer <- arc_open(CCRI_URL) CCRI_Layer
Use Arc Select to isolate the data
NY_CCRI_DF <- arc_select(CCRI_Layer,where = "STATEFP = '36'") NY_CCRI_DF
Publish this data to arcgis online
res <- publish_layer(NY_CCRI_DF, "R-arcgisBridge Upload Test") res '
Unfortunately, once the shapefile is uploaded it collapses and fails to draw any of the more complex geometries - i.e. the entirety of long island
Within the Rstudio environment ,there is no issue with plotting the data.... via the command
plot(NY_CCRI_DF)
The questions I have are: