|
POST
|
My first check would be to see if the "C:\\geometry\\test.gdb" workspace exist on the ArcGIS Server machine. You may want to consider using a scratch or in_memory workspace instead.
... View more
01-13-2016
08:07 AM
|
1
|
1
|
3572
|
|
POST
|
If they are SDE tables then why not just use arcpy.ListTables() to access and work with cursors? If you truly need to access outside of the ESRI stack, I'd start with just issuing the desired T-SQL against the database using pyodbc. This doesn't give you an solution for Stored Procedures but might start you off down that path. Adapted from existing implementation but untested: Update (referencing Sproc with parameters seems pretty straight forward): sqlcursor.execute("{call dbo.SProName(?,?)}", (param1), (param2)) Sample pyodbc: import pyodbc
conn = pyodbc.connect('DRIVER={SQL Server Native Client 11.0};' +
'SERVER=' + servername +
';DATABASE=' + databasename +
';schema=' + schemaname +
';UID=' + username +
';PWD=' + password)
#I'm not totally sold on this being the best choice of sql
sql = """SELECT 1 WHERE EXISTS (SELECT L_HAZARDPROBABILITY.F_EVENT
FROM L_HAZARDPROBABILITY WHERE L_HAZARDPROBABILITY.F_EVENT<10 Or L_HAZARDPROBABILITY.F_EVENT >1000)"""
sqlcursor = conn.cnxn.cursor()
sqlcursor.execute(sql)
sqlrows = sqlcursor.fetchall()
datArray = []
for sqlrow in sqlrows:
datArray.append(sqlrow)
if len(datArray) > 0:
#we have at least 1 row in the array filled by cursor
'do stuff
sqlcursor.close()
... View more
01-12-2016
06:36 AM
|
1
|
1
|
1803
|
|
POST
|
Hi Bruce, Yes, again -- apologies for not posting my complete implementation and just offering bits and pieces. This is all supposed to be lightweight operation and just deal with geometries minus any feature classes and cursors. Thanks again for your input! I learned some things!
... View more
01-08-2016
10:41 AM
|
0
|
0
|
4490
|
|
POST
|
In case my last reply is confusing, Darren's suggested example seems to be what I needed. FYI for others: this is largely an issue of JSON string manipulation work and can be tough to pick out the error in the details. Keep in mind that it's often a good idea to reduce things down to bare minimum, get it working, then apply it to the full implementation -- something easily skipped (like I tend to do!).
... View more
01-08-2016
07:45 AM
|
0
|
0
|
4490
|
|
POST
|
Edit: the issue is an extra "[" and "]" at the start and end of the input array of coords. Super easy to miss with all of the brackets and squiglies but your "feature" array shows the differnce! Your example input of coords: feature = [[1,2],[2,2],[2,3],[1,2]] My input looked like this:
feature = [[[-9020934.359395614, 3186437.9104202176], [-9020934.359395612, 3186323.2548777903], [-9021029.90568097, 3185711.7586515094], [-9021794.27596382, 3185941.0697363648], [-9020934.359395614, 3186437.9104202176]]] But to remove/fix the offending brackets, I had to modify my geo_convert def that takes in the input json string and handles it. It was an easy fix to apply to the 'coordinates' token: def geo_convert(ring_string):
from json import loads, dumps
rings = loads(ring_string)
feat_coll = {'type': 'FeatureCollection',
'features':[]}
for ring in rings:
feat_coll['features'].append(
{'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': ring['rings'][0] #<- this had an extra set of [] wrapping it
}})
print feat_coll
return dumps(feat_coll)
#the input string I am getting
feature_info = """[{"rings":[[[-9020934.359395614,3186437.9104202176],[-9020934.359395612,3186323.2548777903],[-9021029.90568097,3185711.7586515094],[-9021794.27596382,3185941.0697363648],[-9020934.359395614,3186437.9104202176]]]}]"""
#format the string
jsonFrmt = geo_convert(feature_info) Darren, I'm getting a RuntimeError "Point: Input value is not numeric" on this line: polygon = arcpy.Polygon(arcpy.Array([arcpy.Point(*coords) for coords in feature]), inSr) Here's my input JSON: feature_info = """[{"rings":[[[-9020934.359395614,3186437.9104202176],[-9020934.359395612,3186323.2548777903],[-9021029.90568097,3185711.7586515094],[-9021794.27596382,3185941.0697363648],[-9020934.359395614,3186437.9104202176]]]}]""" This is what feature looks like when I print it: [[[-9020934.359395614, 3186437.9104202176], [-9020934.359395612, 3186323.2548777903], [-9021029.90568097, 3185711.7586515094], [-9021794.27596382, 3185941.0697363648], [-9020934.359395614, 3186437.9104202176]]] Any ideas? features = []
features2 = []
feature = v['coordinates']
print feature
polygon = arcpy.Polygon(arcpy.Array([arcpy.Point(*coords) for coords in feature]), inSr)
polygon2 = polygon.projectAs(outSr)
features.append(polygon)
features2.append(polygon2)
print polygon.area
print polygon2.area
... View more
01-08-2016
06:36 AM
|
0
|
0
|
4490
|
|
POST
|
Edit: Bruce -- thanks for your input and example, I'll be able to use this elsewhere I'm sure! I should have posted the full implementation so that you didn't have to guess but I think Darren supplied the exact example I needed. Thanks again. I'm not understanding your example. Where is that SearchCursor set from? I don't have a FeatureClass, just an input JSON string that I need to take in, create the polygon feature of those coordinates, change the spatial reference and then return the coordinate pair of the centroid and the area of that feature.
... View more
01-08-2016
06:29 AM
|
0
|
2
|
4490
|
|
POST
|
You need to make a geometry instance from the array you get out of the geometry feature made by AsShape(). That's what I hoped to accomplish but I don't see how to do this with a polygon! Do you have an example to point to? Thanks a bunch for your input! I can get to populate "features" array, but not sure why it won't set to a polygon for key,value in jsonData.iteritems():
if value == 'FeatureCollection':
pass
else:
for i in value:
try:
for k,v in i.iteritems():
if k == 'geometry':
features = []
featureinfo = v['coordinates']
for feature in featureinfo:
features.append(arcpy.Polygon(arcpy.Array([arcpy.Point(*coords) for coords in feature]), inSr))
#project to output sr
prjpolygon = features.projectAs(outSr) #fails
... View more
01-07-2016
01:46 PM
|
0
|
7
|
4490
|
|
POST
|
Tag: Please help Jason Scheirer After running down the path of geoJSON, I've finally encountered some difficulty in setting the spatial reference on a polygon feature. In the code below, I thought I could get away with somehow setting the spatial ref on arcpy.AsShape() method but now I'm stuck on what to do! The problem seems to be that my polygon.projectAs(outSr) is not working, I presume because the input polygon feature does not have the inSr set? polygon = arcpy.AsShape(v) # <-- does not have a spatial ref at this point
prjpolygon = polygon.projectAs(outSr) Input JSON coordinates are web Mercator (Auxiliary Sphere). Hopefully I'm just missing the obvious. data = {}
feature_info = """[{"rings":[[[-9020934.359395614,3186437.9104202176],[-9020934.359395612,3186323.2548777903],[-9021029.90568097,3185711.7586515094],[-9021794.27596382,3185941.0697363648],[-9020934.359395614,3186437.9104202176]]]}]"""
def geo_convert(ring_string):
from json import loads, dumps
rings = loads(ring_string)
feat_coll = {'type': 'FeatureCollection',
'features':[]}
for ring in rings:
feat_coll['features'].append(
{'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': [ring['rings'][0]]
}})
return dumps(feat_coll)
tmpArr = []
jsonFrmt = geo_convert(feature_info)
jsonData = json.loads(jsonFrmt)
inSr = arcpy.SpatialReference(3857)
outSr = arcpy.SpatialReference(26758)
for key,value in jsonData.iteritems():
if value == 'FeatureCollection':
pass
else:
for i in value:
try:
for k,v in i.iteritems():
if k == 'geometry':
polygon = arcpy.AsShape(v) #cannot set a sr
#project to output sr
prjpolygon = polygon.projectAs(outSr) #does not project
else:
pass
except:
pass
... View more
01-07-2016
12:38 PM
|
0
|
10
|
8020
|
|
POST
|
I don't do much with model builder, but to iterate over each "x" in a workspace... arcpy.env.workspace = <your workspace goes here>
for raster in arcpy.ListRasters():
'perform your additional processing on each raster
for featurceClass in arcpy.ListFeatureClasses():
'do stuff with the FC
for table in arcpy.ListTables():
'do stuff with the table
... View more
01-06-2016
01:13 PM
|
0
|
0
|
2368
|
|
POST
|
It's been a while since I actually ran this, but should work just fine: (updated with corrections) wsIN = "in_memory"
wsOUT = r"H:\Documents\ArcGIS\MyFileGDB.gdb"
arcpy.env.workspace = wsIN
inFCS = arcpy.ListFeatureClasses()
for inFC in inFCS:
desc = arcpy.Describe(inFC)
arcpy.CopyFeatures_management(inFC, wsOUT + "\\" + desc.name)
... View more
01-06-2016
10:48 AM
|
0
|
0
|
2506
|
|
POST
|
Even better solution is to just set proper parameters on the .getArea() method: prjpolygon = polygon.projectAs(outSr)
sqmeters = prjpolygon.getArea('PLANAR','Meters')
... View more
01-06-2016
08:31 AM
|
1
|
0
|
1684
|
|
POST
|
Thank you! I had to cycle thru the types (planar was the ticket) to get these to produce identical results: prjpolygon = polygon.projectAs(outSr)
parea1 = prjpolygon.getArea('PLANAR','Feet')
parea2 = prjpolygon.area
print "\t parea1 Sqfeet : {} ".format(parea1)
print "\t parea2 Sqfeet : {} ".format(parea2) Results: parea1 Sqfeet : 26642367.0 parea2 Sqfeet : 26642367.0
... View more
01-06-2016
08:27 AM
|
1
|
0
|
2218
|
|
POST
|
In an attempt to acquire the area of a polygon feature, I'm seeing some discrepancies between two methods and need some input. In the code below, I'm acquiring what I think is the area in 2 distinctive ways (parea1 and parea2): prjpolygon = polygon.projectAs(outSr)
parea1 = prjpolygon.getArea()
parea2 = prjpolygon.area The result: parea1 Sqfeet : 21767057.9882 parea2 Sqfeet : 26642367.0 Why do these return different values? Which one do I use?
... View more
01-06-2016
08:03 AM
|
0
|
2
|
4904
|
|
POST
|
I think I can just apply some simple math to arrive at a solution but feel free to shoot it down and suggest a better way! prjpolygon = polygon.projectAs(outSr)
parea = prjpolygon.getArea()
sqmeters = parea * 0.09290304
... View more
01-06-2016
07:42 AM
|
0
|
0
|
1684
|
|
POST
|
I'm trying to figure out how to project individual polygon features that I'm constructing from a JSON input that gets parsed from coordinates. The input looks like this: feature_info = """[{"rings":[[[-9050993.00, 3222038.00],[-9049770.00, 3220509.00],[-9047629.00, 3213783.00],[-9054356.00, 3215923.00],[-9050993.00, 3222038.00]]]}]""" I do not have problems creating the polygon, however I need to project the feature (see the inSr and outSr variables for their WKID's). Again, no problems with the projection to that desired system! But the units are in US Foot and I need it to be in Meters. Apparently, this property is read only and does not change it: inSr = arcpy.SpatialReference(3857)
outSr = arcpy.SpatialReference(26758)
outSr.linearUnitName = 'Meter' #this does nothing Then I see that some have successfully just altered the desired output SpatialReference by manipulating the string value of the projection like this, but again, it still doesn't change the unit to meters for me. Maybe you can spot the issue? outSr.loadFromString(re.sub('PARAMETER\[\'Unit\', Foot_US]', 'PARAMETER\[\'Unit\', Meter]', outSr.exportToString()))
print arcpy.SpatialReference.exportToString(outSr)
... View more
01-06-2016
07:13 AM
|
0
|
2
|
3800
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|