|
POST
|
You can create a polygon with the area of interest and clip the data. This polygon feature class can also be used in your environment settings as mask.
... View more
08-28-2014
08:50 PM
|
1
|
1
|
719
|
|
POST
|
The functionality to extract the feature attachments is not limited to the da.cursor. The syntax will be different. The help provides some examples of how to use the cursor in 10.0:ArcGIS Desktop If you have problems creating the proper syntax let me know and I will add the code sample for 10.0. Kind regards, Xander
... View more
08-28-2014
08:41 PM
|
0
|
4
|
2602
|
|
POST
|
I've moved your post into the Python space. You will probably get a much more response here. You can see more on the community structure, and what topics are under each space from the following documents: GeoNet Community Structure ArcGIS Discussion Forums Migration Strategy Thanks! Xander
... View more
08-26-2014
09:36 AM
|
0
|
0
|
1669
|
|
POST
|
It sounds to me that your are not so much trying to do this analysis in a parallel process, but would like to know if you can create a model or script more easily to do the analysis. That is indeed possible. In modelbuilder you can use iterations. Read the following topic to start: A quick tour of using iterators It is also possible to use python to perform this task. Personally I feel more comfortable with python to perform repetitive tasks. You would probably one of the arcpy.List* tools to get a list of the input data you want to process. Next you loop through all the items in the list and for each input item you define the output name and execute the Morans I tool. If you look at the Help page on Spatial Autocorrelation (Global Moran's I) (Spatial Statistics) and scroll down you'll find examples of executing the tool (including OLS and SWM). You can also perform the process manually for one input and go to the Results window and right click on the excuted process which will reveal the option to copy the python snippet. This can also be used to start. Kind regards, Xander
... View more
08-26-2014
09:29 AM
|
2
|
4
|
1927
|
|
POST
|
Remember that Riyas Deen did most of the work. To help you a little in the process of understanding the code, here goes... There are a number of functions that can be reused and help to make the code more readable line 3 - 6 (createMatchingFieldList) uses list comprehensions to create a list of the field names in both featureclasses. The lists are converted to sets which van be used with the & to create a set with only those elements that exist in both sets. The List() converts the resulting set to list Line 8 - 15 (createWhereClause) uses the type of the field (the code will only handle string and numeric fields correctly) and the arcpy.AddFieldDelimiters to add quotes or brackets to the field depending on the datasource. This is powerful way of making code run correctly on different types of data (shapefiles, file, personal and enterprise geodatabases) line 17 and 18 (getPrimaryFieldValues) uses again a list comprehension to create a list of values in a given field. It actually loop through the data and returns the first field r[0] and adds it to a list (hence the square brackets). line 20 and 21 (getSelectCursor) creates a search cursor with the given fields and where clause. line 23 and 24 (diff) returns a list of element which are in list a, but not in list b. The rest of the code does the job: lines 34 - 40 contains the calls to the various functions (creating the list of fields, the list of values for both featureclasses and determining the difference) lines 42 - 47 creates an insert cursor on the destination and loop through the elements in "additions" and inserts the rows (from the source) into the destination lines 49 to 53 uses an update cursor on the destination to remove those features that are in the destination, but not in the source. Kind regards, Xander
... View more
08-25-2014
11:29 AM
|
1
|
5
|
2332
|
|
POST
|
OK, so if we get rid of the "*" as field list it would look something like this. Please note that the code has not been tested on any data.
import arcpy
def createMatchingFieldList(fc1, fc2):
lst1 = [fld.name for fld in arcpy.ListFields(fc1)]
lst2 = [fld.name for fld in arcpy.ListFields(fc2)]
return list(set(lst1) & set(lst2))
def createWhereClause(fc, fld_name, value):
if len(arcpy.ListFields(fc, fld_name)) == 1:
fld = arcpy.ListFields(fc, fld_name)[0]
if fld.type == "String":
where = "{0} = '{1}'".format(arcpy.AddFieldDelimiters(fc, fld_name), value)
else:
where = "{0} = {1}".format(arcpy.AddFieldDelimiters(fc, fld_name), value)
return where
def getPrimaryFieldValues(fc, field):
return [r[0] for r in arcpy.da.SearchCursor(fc, [field])]
def getSelectCursor(fc, flds, whereClause):
return arcpy.da.SearchCursor(fc, flds, whereClause)
def diff(a, b):
return list(set(a) - set(b))
#source = arcpy.GetParameterAsText(0)
#destination = arcpy.GetParameterAsText(1)
#fieldName = arcpy.GetParameterAsText(2)
source = r"C:\tempdelete\PL_TO_LINE.gdb\PL\VERT_TO_POINIT"
destination = r"C:\tempdelete\PL_TO_LINE.gdb\PL\VERT_TO_POINIT_DEST"
fieldName = "ROUTE_LINK_NO"
# create a list of field names which are in both featureclasses
flds = createMatchingFieldList(source, destination)
sourceValues = getPrimaryFieldValues(source, fieldName)
destinationValues = getPrimaryFieldValues(destination, fieldName)
additions = diff(sourceValues, destinationValues)
deletions = diff(destinationValues, sourceValues)
with arcpy.da.InsertCursor(destination, flds) as insertCursor:
for a in additions:
where = createWhereClause(source, fieldName, a)
insertRows = getSelectCursor(source, flds, where)
for r in insertRows:
insertCursor.insertRow(r)
for d in deletions:
where = createWhereClause(destination, fieldName, d)
with arcpy.da.UpdateCursor(destination, flds, where) as deleteCursor:
for d in deleteCursor:
deleteCursor.deleteRow()
Kind regards, Xander
... View more
08-25-2014
10:27 AM
|
1
|
7
|
6702
|
|
POST
|
May have something to do with the fields setting, which is "*": When using "*", geometry values will be returned in a tuple of the x,y-coordinates (equivalent to the SHAPE@XY token). Might be better to construct a list with the field names...
... View more
08-25-2014
09:43 AM
|
0
|
8
|
6702
|
|
POST
|
I changed the code from Riyas Deen a bit:
import arcpy
def createWhereClause(fc, fld_name, value):
if len(arcpy.ListFields(fc, fld_name)) == 1:
fld = arcpy.ListFields(fc, fld_name)[0]
if fld.type == "String":
where = "{0} = '{1}'".format(arcpy.AddFieldDelimiters(fc, fld_name), value)
else:
where = "{0} = {1}".format(arcpy.AddFieldDelimiters(fc, fld_name), value)
return where
def getPrimaryFieldValues(fc, field):
return [r[0] for r in arcpy.da.SearchCursor(fc, [field])]
def getSelectCursor(fc, whereClause):
return arcpy.da.SearchCursor(fc, ["*"], whereClause)
def diff(a, b):
return list(set(a) - set(b))
#source = arcpy.GetParameterAsText(0)
#destination = arcpy.GetParameterAsText(1)
#fieldName = arcpy.GetParameterAsText(2)
source = r"C:\tempdelete\PL_TO_LINE.gdb\PL\VERT_TO_POINIT"
destination = r"C:\tempdelete\PL_TO_LINE.gdb\PL\VERT_TO_POINIT_DEST"
fieldName = "ROUTE_LINK_NO"
sourceValues = getPrimaryFieldValues(source, fieldName)
destinationValues = getPrimaryFieldValues(destination, fieldName)
additions = diff(sourceValues, destinationValues)
deletions = diff(destinationValues, sourceValues)
with arcpy.da.InsertCursor(destination, ["*"]) as insertCursor:
for a in additions:
where = createWhereClause(source, fieldName, a)
insertRows = getSelectCursor(source, where)
for r in insertRows:
insertCursor.insertRow(r)
for d in deletions:
where = createWhereClause(destination, fieldName, d)
with arcpy.da.UpdateCursor(destination, ["*"], where) as deleteCursor:
for d in deleteCursor:
deleteCursor.deleteRow()
How did you define your field name? Is the intermediate geodatabase a file geodatabase or a personal one? Kind regards, Xander
... View more
08-25-2014
08:21 AM
|
2
|
11
|
6702
|
|
POST
|
I suppose you want to determine the agricultural production per parcel. You can do this in raster or vector format. Raster (spatial analyst extension required) Convert your parcels to raster (use an unique identifier for the parcels in the process) and use the Combine (Spatial Analyst) to create a new raster. Use the attribute table to extract the statistics on agricultural production per parcel. Vector Convert your classification result to polygons. Use the Union tool to combine both featureclasses. Use the attribute table to extract the statistics on agricultural production per parcel. Kind regards, Xander
... View more
08-25-2014
06:40 AM
|
0
|
0
|
695
|
|
POST
|
It seems there is something wrong with the transportType "esriTransportTypeURL". I changed the code to use urllib and urllib2 and it returned the following error: {"error":{"code":400,"message":"","details":["'transportType' parameter is invalid"]}} I changed the transportType to esriTransportTypeEmbedded and that did return a link to a ZIP file.
import json
import urllib
import urllib2
payload={"geometry": '',
"geometryType": "esriGeometryEnvelope",
"inSR": '',
"layerQueries": '',
"layers": "0",
"replicaName": "read_only_rep",
"returnAttachments": 'true',
"returnAttachmentsDataByUrl": 'true',
"transportType": "esriTransportTypeEmbedded",
"async": 'false',
"syncModel": "none",
"dataFormat": "filegdb",
"replicaOptions": '',
"f": "json"}
url = 'http://services2.arcgis.com/Pw6oQMuXLspbq6zz/arcgis/rest/services/SON_ROADS/FeatureServer/createReplica'
data = urllib.urlencode(payload)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
json_out = response.read()
print json_out
This printed: {"transportType":"esriTransportTypeUrl","responseUrl":"http://services2.arcgis.com/Pw6oQMuXLspbq6zz/ArcGIS/rest/services/SON_ROADS/replicafiles/8c8720356d6e428882414e343f1dee9d.zip"} The ZIP contains the fgdb. Kind regards, Xander
... View more
08-24-2014
09:19 PM
|
1
|
2
|
1689
|
|
POST
|
Hi Gianni, It sounds like a bit of an overkill to buy ArcGIS just for converting a set of json files. I'm sure there are other (free) options that can do the job. You mentioned that you want the points inside the file converted to WGS1984. The content of the json you send is a polygon (area). In case you want to use ArcGIS for it (maybe you can download a trail version), you can use some python script to convert the file. Since at this location I only have access to 10.1, the options to convert json are a bit limited. Below you'll find a Python script (using ArcGIS) that converts the json to a kmz file (WGS1984). I'm sure there must be easier ways to do this. I'll attach the kmz file so you can have a look if this type of information is what you ware looking for.
import arcpy, json
arcpy.env.overwriteOutput = True
json_file = r"D:\Xander\GeoNet\SanPietroJSON\json\SanPietro.json"
out_shp = r"D:\Xander\GeoNet\SanPietroJSON\shp\SanPietro_merc.shp"
out_shp_wgs = r"D:\Xander\GeoNet\SanPietroJSON\shp\SanPietro_wgs84.shp"
out_kmz = r"D:\Xander\GeoNet\SanPietroJSON\kmz\SanPietro.kmz"
# spatial references
sr_in = arcpy.SpatialReference(102100) # Web Mercator
sr_wgs = arcpy.SpatialReference(4326) # WGS 1984
# process json file
dct = eval(open(json_file).read())
lst = dct["results"]
dct2 = lst[0]
geom = dct2["geometry"]
rings = geom["rings"]
# create feature(s)
features = []
for feature in rings:
features.append(arcpy.Polygon(
arcpy.Array([arcpy.Point(*coords) for coords in feature])))
# create featureclass (shp)
arcpy.CopyFeatures_management(features, out_shp)
# define projection
arcpy.DefineProjection_management(out_shp, sr_in)
# project to WGS1984
arcpy.Project_management(out_shp, out_shp_wgs, sr_wgs)
# create featurelayer
arcpy.MakeFeatureLayer_management(out_shp_wgs, "WGSpoints")
# convert to KMZ
arcpy.LayerToKML_conversion("WGSpoints", out_kmz)
Kind regards, Xander
... View more
08-22-2014
01:56 PM
|
1
|
0
|
3606
|
|
POST
|
It really depends on the tools you have available and are planning to use and what type of result you want to obtain. Let´s say you have access to ArcGIS for Desktop. In that case you will have to convert the json files to a single or multiple featureclasses using the Web Mercator projection. The next step is to project the featureclasses to WGS 1984 (if that is what you want). What do you want to do with the result? To avoid doing this by hand, you can create a python script to do this. If you are willing to provide more information on the folder structure where you have stored the json file and the corresponding naming or are willing to post a few example files, I might be able to create a script to translate the coordinate to WGS 1984. Kind regards, Xander
... View more
08-21-2014
09:20 AM
|
0
|
2
|
3606
|
|
POST
|
Hi Greg, The only file in the ZIP file is an XML file called "TabSummary.dbf.xml" (or at least this is what passed my firewall). In case you know the names of the double fields you want to maintain untouched, you would have to exclude those from the list of fieldnames. This can be done like this (see code below). the flds_exclude contains a list of fieldnames that should remain untouched flds_touse is a new list where all the items from the exclude list are remove from the list of double fields set() is used to be able to do this type of comparisons with lists, after this the set is converted to a list again
import arcpy
arcpy.env.workspace = r'G:\users\gis\gbacon\Watershed_Testing\valleyave\WatershedDelineation.gdb'
tbl = "TabSummary"
fldlist = [fld.name for fld in arcpy.ListFields(tbl,"","Double")]
flds_exclude = ["myFieldname1", "myFieldname2", "myFieldname3"]
flds_touse = list(set(fldlist) - set(flds_exclude))
with arcpy.da.UpdateCursor(tbl, flds_touse) as cursor:
for row in cursor:
i = 0
for fld in flds_touse:
row = row / 43560
i += 1
cursor.updateRow(row)
Kind regards, Xander
... View more
08-21-2014
09:12 AM
|
0
|
1
|
1476
|
|
POST
|
I think you found out. Thanx, hope the tool will produce that data you're looking for...
... View more
08-21-2014
08:34 AM
|
0
|
0
|
1728
|
|
POST
|
some pointers (without having seen the data): are you sure that all double fields need to be updated? the fldlist in your case is a list that contains field objects, but the cursor will need a list or tuple of field names. I changed this on line 4 for each row you will need to loop through the fields and calculate the new values (see line 8 - 11)
import arcpy
arcpy.env.workspace = r'G:\users\gis\gbacon\Watershed_Testing\valleyave\WatershedDelineation.gdb'
tbl = "TabSummary"
fldlist = [fld.name for fld in arcpy.ListFields(tbl,"","Double")]
with arcpy.da.UpdateCursor(tbl, fldlist) as cursor:
for row in cursor:
i = 0
for fld in fldlist:
row = row / 43560
i += 1
cursor.updateRow(row)
Haven't tested it though. Since you are changing the input data, test it with a copy of the data. Also don't run the code more than once on the same data... Kind regards, Xander
... View more
08-21-2014
08:32 AM
|
0
|
3
|
1476
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-09-2020 09:26 AM | |
| 6 | 12-20-2019 08:41 AM | |
| 1 | 01-21-2020 07:21 AM | |
| 2 | 01-30-2020 12:46 PM | |
| 1 | 05-30-2019 08:24 AM |
| Online Status |
Offline
|
| Date Last Visited |
Tuesday
|