Select to view content in your preferred language

Create a Multi polygons feature issue

210
2
Jump to solution
04-21-2024 01:50 PM
DominicRoberge2
Occasional Contributor III

Hello,

I am trying to create a multi polygons feature into a hosted feature layer and I am stuck! I am creating the array of rings on the fly and trying to replay the array of rings from my geometry template. When I print the information, everything looks good, but when I try to create a the feature, my "array" of rings is really a "string" of rings. 

below is the code and the issue I am facing

Any help would be much appreciated

Thanks!

geomList = []
geoArray = []
for d in search_SAhistcountTVMAXFeat:
    if d.attributes['LandRecordsIDCount']>1:
        print(d)
        #Select at records with that specific LandRecordID
        fExpression = "LandRecordsID='" + d.attributes['LandRecordsID'] +"'"
        print(fExpression)
        SLHFLcount = LandHFL.query(where=fExpression )
        feat_list = SLHFLcount.features

        ### NEED TO EXTRACT SINGLE PART FOR EACH POLYGONS
        strPoly =''
        strPoly = '['
        print("RAW Geometry ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
        for f in feat_list:
            print(f.geometry['rings']) 
            print("")
            strPoly = strPoly+str(f.geometry['rings'])[1:-1]+','
        strPoly = strPoly[:-1]
        strPoly= strPoly+']'
        print("All Geometry as String~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
        print(strPoly)
        print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
        print("          ")

        #single part template
        drtest = {'rings': [[[-10478969.9507, 5105644.4034], [-10477947.6054, 5105639.626], [-10477952.3827, 5104555.1757], [-10478998.6146, 5104559.953], [-10479017.7238, 5105333.8779], [-10478979.5053, 5105338.6552], [-10478969.9507, 5105644.4034]]],'spatialReference': {'wkid': 102100,'latestWkid': 3857}}
        print("Rings from template")
        print(drtest["rings"])
        print(" ")
        print("after update")
        drtest["rings"] = strPoly   
        print(drtest["rings"])

        print("Creating Template-------------------------")        
        features_to_be_added = []
        template_hostedFeature = deepcopy(SLHFLcount.features[0])
        template_hostedFeature

        print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
        drShape = drtest  #geom_union_b
        print(drShape)
        new_feature = deepcopy(template_hostedFeature)
        print("")
        # assign the updated values
        new_feature.geometry = drShape    #output_geometry[0]
        new_feature.attributes['LandRecordsID'] = d.attributes['LandRecordsID']
        #new_feature.attributes['Property'] = ''
        print("Final new feature-------------------------")
        print(new_feature)

results:

DominicRoberge2_0-1713732557513.png

 

0 Kudos
1 Solution

Accepted Solutions
Clubdebambos
Occasional Contributor III

Hi @DominicRoberge2 

You are converting the geometry to string.

strPoly = strPoly+str(f.geometry['rings'])[1:-1]+','

 

when you need to keep it as the nested lists and manipulate the lists instead to create your new geometry..

~ learn.finaldraftmapping.com

View solution in original post

0 Kudos
2 Replies
Clubdebambos
Occasional Contributor III

Hi @DominicRoberge2 

You are converting the geometry to string.

strPoly = strPoly+str(f.geometry['rings'])[1:-1]+','

 

when you need to keep it as the nested lists and manipulate the lists instead to create your new geometry..

~ learn.finaldraftmapping.com
0 Kudos
DominicRoberge2
Occasional Contributor III

I had been looking at this issue for too long 🙂

got it

geoArray.append(f.geometry['rings'][0])

Thanks!

D