AnsweredAssumed Answered

Intersect between multiple points and polygons / gis.content.import_data error "The following rows could not be written to the table: 0"

Question asked by H.Bouckaert_westernpower on Nov 5, 2018



Irrespective of what I try I cannot do an intersect between multiple points and multiple polygons and neither can I save the results from the intersect as a new feature layer collection in AGOL. Here is what I do: 


From my AGOL folder I get a polygon layer "cadastre_layer" and a point layer "poi_layer" (both are layer objects). 


My aim is to generate an output FeatureSet object from all intersects between 3 points and 3 polygons, but I cannot seem to do this. All the examples I have found only use a single point as the object to select with. So I tried this: 


I create a query object from the point layer: 

poi_queryResult = poi_layer.query()


for poi_geom in poi_queryResult.features:
    cadastre_filter_result = cadastre_layer.query(where='1=1',        geometry_filter=filters.intersects(poi_geom.geometry),return_all_records=True)


But then "cadastre_filter_result" merely only contains the result of the last point geometry passed through the loop.


So I tried to create a geometry object that would contain all three points and also ensures the right projection:  


output_geometry = geometry.project(geometries = [f.geometry for f in poi_queryResult.features],in_sr = 3857, out_sr =3857,  gis = gis)   


But I cannot pass  output_geometry into the geometry_filter (above). I tried several other things, but nothing seems to work. 


So my first question is: how do you do a spatial intersect between several points and several polygons? 


The second problem is that I would like to use gis.content.import_data to import the FeatureSet (cast to a DataFrame) so I end up with a new Feature Layer Collection in my home folder. However that does not work either: 


gis.content.import_data(df=cadastre_filter_result.df, target_sr =3857,title="Cadaste Spatial Query Results" )  


There is a new object in my home folder in AGOL, but it contains no data. Indeed the error from executing the above line is: "The following rows could not be written to the table: 0"


But if I try to save the results of the spatial query to a shape file, I get (at least) one polygon (presumably the  one that intersected with the last point). So this works:'my_layer',save_location=r'C:\Data')


So my second question is, how do I get gis.content.import_data to work on the results of the spatial intersect?