'geometry' parameter is invalid when creating replica

513
2
Jump to solution
03-15-2018 07:28 PM
simoxu
by MVP Regular Contributor
MVP Regular Contributor
Unable to create replica. Please check your parameters. 'geometry' parameter is invalid

You are guaranteed to see this error when using geometry filter as parameter to create a replica in the latest ArcGIS API for Python (V1.4.0)!

in the signature of function FeatureLayerCollection.replicas.create, it states geometry_filter parameter as the following:

geometry_filter - spatial filter from arcgis.geometry.filters module to filter results by a                      spatial relationship with another geometry

Following this instruction, I constructed an filter object:

flc=gis.content.get('1bedbababababababab5')
aa=flc.layers[0]
fset=aa.query()

geom=None
f=None
geo_filter=None

count=len(fset.features)
if count>0:
    f=fset.features[0]
    geom=f.geometry
if geom is not None:
    geo=Polygon(geom)
    geo_filter=arcgis.geometry.filters.contains(geo,'102100')

.....

fs = FeatureLayerCollection(url, gis)

......

result = fs.replicas.create(replica_name='test', layers='0,1,3,4,6,8,10,12,13,15', layer_queries=layerQs, 

geometry_filter=geo_filter,
replica_sr='102100',
transport_type="esriTransportTypeUrl",
return_attachments=returnAttach,
return_attachments_databy_url=returnAttachbyURL,
asynchronous=False,
attachments_sync_direction=attachSyncDirect,
sync_model="none",
data_format=format,
replica_options=None,
wait=False,
out_path=r'C:\Temp\fs_replicas',
sync_direction='bidirectional',
target_type="client")

geo_filter will crash the function, 100%.

Why?

json representation of geo_filter object was posted to the following endpoint (REST Resource)

http:// <featureservice-url>/createReplica

This resource only accepts geometry, geometryType,inSR, but not geometry.filters format. click the following link to find the acceptable parameters createReplica

Create Replica—ArcGIS REST API: Services Directory | ArcGIS for Developers 

The difference between the acceptable geometry and geometry.filters? just give you an example:

geometry:

{'rings': [[[14884284.6024463, -3776313.01482297], [15552038.4815454, -3766529.07520247], [15657215.8324658, -4475864.69768871], [15192478.700492, -4307091.73923509], [14884284.6024463, -3776313.01482297]]]}

geometry.filters.contains:

{'geometry': {"rings": [[[14884284.6024463, -3776313.01482297], [15552038.4815454, -3766529.07520247], [15657215.8324658, -4475864.69768871], [15192478.700492, -4307091.73923509], [14884284.6024463, -3776313.01482297]]]}, 'geometryType': 'esriGeometryPolygon', 'spatialRel': 'esriSpatialRelContains'}

How to fix it?

Pretty simple, only 3 lines of code.

in the layer.py under the following folder:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis-1.3.0-py3.6.egg\arcgis\features

line 1453 (v1.3.0) / line1467 (v1.4.0):

if geometry_filter is not None and \

                        isinstance(geometry_filter, dict):
##comment out the original code and get geometry, geometryType and inSR seperately!

##params['geometry'] = geometry_filter
params['geometry'] = geometry_filter['geometry']
params['geometryType'] = geometry_filter['geometryType']
params['inSR'] = geometry_filter['inSR']
#params.update(geometry_filter)

Conclusion:

It seems just an oversight in the API development, and it won't take much to fix.

But, this bug should not slip through the QA process, because creating replica is such an important function, and using geometry to clip data and create a replica is such a common GIS practice.

I guess the bug has been around for quite a while, it's already v1.40 ! Please fix it.

This puzzled me for the whole afternoon, I hope others can avoid it.

Atma Mani

John Yaist

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
RohitSingh2
Esri Contributor

Hi Simo,

Thank you for reporting this. We've included the fix and it will be part of the next update.

Thanks,

Rohit

View solution in original post

2 Replies
RohitSingh2
Esri Contributor

Hi Simo,

Thank you for reporting this. We've included the fix and it will be part of the next update.

Thanks,

Rohit

View solution in original post

simoxu
by MVP Regular Contributor
MVP Regular Contributor

Hi Rohit, 

Thanks for confirming it.

Cheers,

Simo

0 Kudos