Select to view content in your preferred language

converting a feature class to numpy array?

1777
2
06-06-2021 07:33 AM
DanielFuller
Emerging Contributor

Hello

I have a raster layer and a feature class that I need to combine. I have been advised that the best way to do this would be through numpy arrays.

converting the raster layer was simple enough 

rast_nparr = arcpy.RasterToNumPyArray("UKJstdRM")

however i'm having real trouble getting the feature class to convert. I should make it obvious this is my first time using the library so i don't really understand how it works so this might be a very simple fix

 

at first I thought it was because everything was contained in a layer file and not a feature class 

feature_class = arcpy.CopyFeatures_management("UKJ_areas.lyr", "UKJ_FC")
fet_nparr = arcpy.da.FeatureClassToNumPyArray (feature_class, ["Shape","objectid","nuts315cd","nuts315nm","MEAN_parti"])

 

however when I run this code i get an error indicating that "a column was specified that does not exist"

i've tried removing some columns to try and fix the issue with no luck so i'm assuming i'm using the functions wrong.

 

Hope someone can help

 

Tags (3)
0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

 A little gander at the help topic will give you some suggestions regarding the shape and id fields

FeatureClassToNumPyArray—ArcGIS Pro | Documentation

 

arr = arcpy.da.FeatureClassToNumPyArray(fc, ["OID@", "SHAPE@X", "SHAPE@Y", "Blah"])

 

Addendum

Even if you convert the vector to an array, at best you will get the points forming the perimeter of the polygon and not the intervening space.  If you want to work with the raster and the polygon, then convert the polygon to raster, then use RasterToNumPyArray for both.

 


... sort of retired...
JayantaPoddar
MVP Esteemed Contributor

What do you mean when you say "I have a raster layer and a feature class that I need to combine"? Do you want to create a statistics (SUM, MEAN, MAX, etc.) or create a unique combination of the Raster and a Field value(s) of Feature Class?

Converting the Vector to Raster (using desired value field) could be an option. Keep the Cell size and Snap Raster setting as your Raster layer.

Using the above output Raster with your original Raster layer, you could do a Raster Calculation as desired.

* I am assuming that you have an ArcGIS Desktop Advanced + Spatial Analyst extension License.



Think Location
0 Kudos