|
POST
|
Many thanks for your reply, Jason, and apologies for not checking my setup. The machine I was using yesterday did not have Service Pack 1 installed. Today I am with SP1 and the JSON property on geometries works as a charm. I couldn't find out-of-the-box arcpy conversion to GeoJSON but the functions you pointed out in your geojson-madness library do the job. Below I am adding my notes on this topic in context of Python/JavaScript in case anyone is interested. Corrections and additions are more than welcome. Filip. Converting geometries between esri JSON, GeoJSON, and arcpy objects In Python with arcpy: # GeoJSON --> esri Python : arcpy.AsShape(x)
# GeoJSON --> esri JSON : arcpy.AsShape(x).JSON
# esri Python --> GeoJSON : geojson-madness.geometry_to_struct(x)
# esri Python --> esri JSON : x.JSON
# esri JSON --> esri Python : arcpy.AsShape(x, True)
# esri JSON --> GeoJSON : geojson-madness.geometry_to_struct(arcpy.AsShape(x, True)) In JavaScript with esri js api and Terraformer: // esri JSON --> esri JSAPI : esri.geometry.jsonUtils.fromJson(json)
// GeoJSON --> esri JSAPI : Terraformer.ArcGIS.convert(...)
// esri JSON --> GeoJSON : Terraformer.ArcGIS.parse(...)
// esri JSAPI --> GeoJSON : Terraformer.ArcGIS.parse(...)
// esri JSAPI --> esri JSON : esri JSON is representation of esri JSAPI
// GeoJSON --> esri JSON : Terraformer.ArcGIS.convert(...) Support for spatial reference in json is generally poor. Information about coordinate system is often lost in translation to different format. Often WGS84 is the only officially supported coordinate system. Therefore, extra care must be taken to handle coordinate systems properly on both server and client side. Spatial reference in GeoJSON can be defined on any object by the 'crs' member, which is inherited and should not be overridden on children. For example: crs_wgs84 = {'type': 'EPSG', 'properties': {'code': 4326}}
crs_osgb = {'type': 'EPSG', 'properties': {'code': 27700}}
Spatial reference is esri JSON can be defined as WKT or WKID. For example: //{"wkid" : <wkid>, "latestWkid" : <wkid>, "vcsWkid" : <wkid>,"latestVcsWkid" : <wkid>}
var web_mercator = {"wkid" : 102100, "latestWkid" : 3857 }
var osgb = {"wkid": 27700}
Notable Python libraries import arcpy
import json
from osgeo import gdal
from osgeo import ogr
import shapely # https://pypi.python.org/pypi/Shapely
import pysal # http://pysal.readthedocs.org/en/latest/index.html
import geojson-madness # https://github.com/jasonbot/geojson-madness Notable JavaScript libraries Terraformer https://github.com/Esri/Terraformer proj4js http://trac.osgeo.org/proj4js/ geojson-utils https://github.com/Esri/geojson-utils koop (js server) https://github.com/Esri/koop Other notes ArcGIS 10.2 has tools 'JSON to Features' and 'Features to JSON' tools. ogr2ogr should be able to convert formats to OGRGeoJSON. http://www.gdal.org/ogr/drv_geojson.html ogr2ogr -f GeoJSON test.json "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hydrography/Watershed173811/FeatureServer/0/query?where=objectid+%3D+objectid&outfields=*&f=json" OGRGeoJSON There is an ArcGIS Server Object Extension that adds support for GeoJSON (didn't try it personally) https://github.com/geobabbler/AGSOpenFormats Somebody already had an ArcGIS Idea RESOURCES GeoJSON Specification:http://geojson.org/geojson-spec.html esri JavaScript geometries: https://developers.arcgis.com/javascript/jsapi/geometry-amd.html http://www.esri.com/industries/landing-pages/geoservices/~/media/Files/Pdfs/library/whitepapers/pdfs/geoservices-rest-spec.pdf http://resources.arcgis.com/en/help/arcgis-rest-api/#/Geometry_Objects/02r3000000n1000000/
... View more
04-01-2014
02:47 AM
|
3
|
1
|
9312
|
|
POST
|
Hi, I want to be able to convert geometries between GeoJSON [1], esri JSON [2, 3], and esri Python objects [4] using ArcGIS 10.1 SP1. [1] http://geojson.org/geojson-spec.html [2] http://resources.arcgis.com/en/help/main/10.1/index.html#//018v0000004m000000 [3] https://developers.arcgis.com/javascript/jsapi/geometry-amd.html etc. [4] http://resources.arcgis.com/en/help/main/10.1/index.html#/Geometry/018z00000070000000/ Converting GeoJSON to esri Python using arcpy.AsShape as described in [2] works. However, converting esri JSON to esri Python described in example 6 on the same help page [2] raises an error. I understand the error but none of my experiments worked and this example is from the official help. esri_json = {"paths" : [[[-97.08, 32.8], [-97.05, 32.6], [-97.06, 32.7], [-97.07, 32.6]], [[-97.4, 32.5], [-97.2, 32.75]]], "spatialReference" : {"wkid" : 4326}} polyline = arcpy.AsShape(esri_json, True) >>> # returns Traceback (most recent call last): File "<editor selection>", line 1, in <module> TypeError: AsShape() takes exactly 1 argument (2 given) I believed it was possible to get esri JSON from esri Python using the JSON property on geometry objects [4], but this consistently fails with errors like: Traceback (most recent call last): File "<editor selection>", line 6, in <module> AttributeError: 'PointGeometry' object has no attribute 'JSON' Do you know about a reliable way of converting esri geometries to GeoJSON in Python? I would be grateful for any comments. Filip.
... View more
03-31-2014
05:53 AM
|
0
|
4
|
21396
|
|
POST
|
Hi rafaelruas, If I understood correctly what you want to do, the code below should work for you. # The code below adds one point at a time to a selection and
# calculates area of convex hull of the selection.
# Output is a text file (or table) with with two columns.
# First column holds number of points selected,
# second column holds total area of the hull.
# Provided you want to use all points in the feature class.
# I recommend you use square metres to get the area and do
# the conversion yourself if you need to. If square metres
# result in too large numbers, use square kilmetres.
import arcpy
# PARAMETERS
in_points = r'C:\temp\base.gdb\pts'
# column indicating in what order to add points to the curve
# should be integers from 1 to N by 1
sort_field = 'OBJECTID'
out_results = r'c:\temp\results.txt'
out_delim = ","
# we need to store the hull temporarily;
# there are more ways how to deal with intermediate data, this is a simple one
arcpy.env.overwriteOutput = True
tmp_hull = r'c:\temp\hull.shp'
# WORK
# write header for result file
with open(out_results, "w") as fl:
header = out_delim.join(("PT_COUNT", "M_SQ"))
fl.write(header + "\n")
# total number of points
n = int(arcpy.GetCount_management(in_points).getOutput(0))
# we need a feature layer in order to make quick selections
in_points_lyr = arcpy.management.MakeFeatureLayer(in_points, "points").getOutput(0)
for i in range(n):
print i
# add another point to the selecition
w_clause = '"%s" < %s' % (sort_field, i + 1) # e.g. OBJECTID < 1, OBJECTID < 2, ...
arcpy.management.SelectLayerByAttribute(in_points_lyr, "NEW_SELECTION", w_clause)
# counstruct convex hull
hull = arcpy.management.MinimumBoundingGeometry(in_points_lyr, tmp_hull, "CONVEX_HULL", "ALL").getOutput(0)
# get the area of the convex hull
# (if you coordinate system units are metres)
ara = 0
with arcpy.da.SearchCursor(hull, ["SHAPE@AREA"]) as sc:
for row in sc:
ara += row[0] # should be just one row anyway
# write results for i into the result file
with open(out_results, "a") as fl:
result = out_delim.join((str(i + 1), str(ara)))
fl.write(result + "\n")
print("Script completed.")
# if you want to import the text file into ArcGIS, do
arcpy.management.CopyRows(out_results, r"c:\temp\results.dbf")
Hope this helps, Filip.
... View more
03-26-2014
02:59 PM
|
0
|
4
|
1271
|
|
POST
|
Hi, Strange. I thought in-memory objects like layers and in_memory feature classes are deleted when a script finishes, but anyway... Make sure that by the end of each script you delete the temporary feature classes (the actual data) as well as the temporary layers (in-memory objects pointing to the data). I would love to hear how you guys do this and if there is good practice that really works. So far in my scripts I have been doing something like this (pseudo-code): import arcpy # start of script try: todlt = [] # list to store everything I want to delete in the end. # ... body of the script, whatever ... my_buffer = arcpy.Buffer_analysis(...).getOutput(0) todlt.append(my_buffer) # if my_buffer is a temporary feature class my_buffer_lyr = arcpy.MakeFeatureLayer_management(my_buffer, 'lyrname', ...).getOutput(0) todlt.append(my_buffer_lyr) # my_buffer_lyr is a temporary feature layer # ... rest of the body of script ... except arcpy.ExecuteError as e: # handle ... except Exception as e: # handle ... finally: # cleanup if 'todlt' in dir(): for dl in todlt: try: arcpy.Delete_management(dl) except: arcpy.AddWarning('Could not delete temporary data ' + str(dl)) By the way, I often use functions from my arcapi repository you may want to check out: https://github.com/NERC-CEH/arcapi Specifically, function dlt() comes handy for the cleanup: if 'todlt' in dir(): for dl in todlt: ap.dlt(dl) and function tstamp is useful to generate temporary layer names: my_buffer_lyr = arcpy.MakeFeatureLayer_management(my_buffer, "lr" + ap.tstamp(tf = "%H%M%S") , ...).getOutput(0) Filip.
... View more
03-24-2014
03:36 PM
|
1
|
0
|
5808
|
|
POST
|
Indeed, use arcpy.GetCount_management. In order to limit the number of record by a where clause, create a feature layer (or table view) first. fc = r'c:\path\to\fc'
w = '"OBJECTID" < 10'
lr = arcpy.MakeFeatureLayer_management(fc, 'tmp_layer', w).getOutput(0)
result = int(arcpy.GetCount_management(lr).getOutput(0))
arcpy.Delete_management(lr) # deletes the layer, not the feature class data
# result is 9
... View more
03-22-2014
02:40 AM
|
1
|
0
|
15616
|
|
POST
|
Hi, thanks for your reply; unfortunately in both cases I get: The module "c:\WatershedSOE.Manager.dll" was loaded but the entry-point DllUnregisterServer was not found. Make sure that "c:\WatershedSOE.Manager.dll" is a valid dll or OCX file and then try again. I found three entries that have 'WatershedSOE' in them in the registry, each with a CLSID entry underneath: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\WatershedSOE.WatershedSOE HKEY_LOCAL_MACHINE\SOFTWARE\Classes\WatershedSOE.ArcCatalog.WatershedPropertyPage HKEY_LOCAL_MACHINE\SOFTWARE\Classes\WatershedSOE.ArcCatalog.PropertyForm Does it make sense to remove these manually or will it just create more problems? Filip.
... View more
03-20-2014
12:33 AM
|
0
|
0
|
508
|
|
POST
|
Hello, We have a server that has been upgraded from 10.0 to 10.2 but one server object extension was not removed before unistalling 10.0. Is it possible to un-register this server object extension (a single .dll) now that we are on 10.2? I tried running the following in cmd.exe: "C:\Program Files\Common Files\ArcGIS\bin\ESRIRegAsm.exe�?� /u "C:\WatershedSOE.Manager.dll" but I get a message complaining about missing dependencies: Unregistration failes. Could not load file or assembly 'file:///c:\watershedsoe.manager.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format. Any, hints welcome. Filip. (Sorry for duplicating, originally I posted similar question into a thread about Java server and I realized most people who could answer it won't see it there.)
... View more
03-19-2014
08:07 AM
|
0
|
3
|
623
|
|
POST
|
Hello, I also need to unregister an SOE originally created for version 10. The machine got upgraded to 10.2.0 but the SOE was not unregistered. (All .NET in this case). Now when I call 'ESRIRegAsm.exe ... /p:desktop /u ...' or 'regasm.exe ... /codebase /u' I get something like "Could not load file or assembly 'ESRI.ArcGIS.ServerManager, Version=10.0.0.0, Culture=...' or one of its dependencies. The system cannot find the file specified". Is there a way to get rid of the SOE without complete reinstallation of the machine? It creates problems when I try to publish a pythin script as a geoprocessing service - the validation window has error 00178: Data: C:\WatershedSOE.Manager.dll, used by Script Tstcd From Point cannot be copied to the server. I don't use the extension in the script anyway. Any hints welcome! Filip.
... View more
03-18-2014
09:59 AM
|
0
|
0
|
810
|
|
POST
|
Hi, Search cursor is read only. You have to use update cursor like so: in_fc = r'path/to/your/feature_class'
with arcpy.da.UpdateCursor(in_fc, ['Cutwidth', 'Toothware']) as uc:
for row in uc:
# with update cursor you can read data
cutwidth = row[0]
toothware = row[1]
# but also update them (use whatever formulas you need)
if cutwidth == 8:
row[1] = cutwith + 10.0
elif cutwidth == 12:
row[1] = cutwith * cutwidth - 15.0
elif cutwidth == 16:
row[1] = cutwith * 0.5 + 20.0
else:
row[1] = -9999
# don't forget to store your changes:
uc.updateRow(row)
I recommend you look at description and examples in help too. Hope this helps. Filip.
... View more
03-16-2014
10:37 AM
|
0
|
0
|
512
|
|
POST
|
The cx_Oracle module digmapper mentioned is developed by Oracle but some people prefer pyodbc module. In any case you need the Instant Oracle Client installed on the computer that will connect to your Oracle database. If the client has not been installed, it may take a while to figure out what version you need to install and how. The solution you propose should work but I am thinking there must be an easier way. I'd try to add the table to ArcMap using one of the many options ( oledb connection Enterprise" rel="nofollow" target="_blank">http://resources.arcgis.com/en/help/main/10.1/index.html#//00290000003q000000]Enterprise database connection other...? you may need to use Make Query Table tool ) and publish the document as a service (if validation allows you to do that). If you can manage to register the database in your Server's data stores, will the service reflect changes in the database instantly? If you don't want instant changes, you might need to go with the approach you outlined. Filip.
... View more
03-15-2014
03:45 AM
|
0
|
0
|
1315
|
|
POST
|
Hi, Assume the path to your connection file is stored in variable 'con'. Have you tried setting env.workspace to something else and calling arcpy.ClearWorkspaceCache_management(con) before you try arcpy.Delete_management(con)? It is not the same as disconnecting via ArcCatalog but it's worth a try. If it doesn't help, is os.remove(con) an option? Filip
... View more
03-09-2014
03:40 PM
|
0
|
0
|
2363
|
|
POST
|
Hello and thanks for such a great support! I am so glad to see that you are on board with this and that some of you have already contributed. Great stuff! The best way to contribute code is exactly how Caleb did - using github. That is of course if you are already familiar with github (or have time and will to explore it). I totally understand you might not want to (or don't have time to) learn about github. In that case we can: post ideas and code into this thread post links to other discussions, blog posts, sites etc. that have some specific and (almost) ready to use code send emails to contact( at )filipkral.com, although I would prefer github and this thread to keep it open for everyone. In any case, I believe it is clear (and I'll clarify this in the README) that by contributing code to arcapi you are releasing the code under the Lesser General Public License v3. To point out just 3 things I think are awesome about github: It is a version control system which makes managing changes easy. It allows discussions about very specific bits of code. It is quite transparent who contributed and to what extent. Last thing to say at this point: it seems I'm able to review any new contributions about once a weak. If I don't react straight away, it's because I don't want to rush the code too much, but eventually I'll reply. So Chris, I'll consider your functions soon, thanks. Keep it coming! Filip.
... View more
03-05-2014
02:30 PM
|
0
|
0
|
1734
|
|
POST
|
Hi, I am having trouble implementing some functionality we have on our 9.3 and 10.0 servers with version 10.2 (all internal servers so cannot share URLs) I need to run a query against a feature class stored in Oracle (ArcSDE 9.3) with where clause that reads something like this (is generated from a mouse-click): sdo_nn(shape, mdsys.sdo_geometry(2001, 81989, mdsys.sdo_point_type(385878.8,247670.9,null),null,null), 'sdo_num_res=1', 1) = 'TRUE' AND sdo_within_distance(shape , mdsys.sdo_geometry(2001, 81989, mdsys.sdo_point_type(385878.8,247670.9, null), null, null),'distance=250 UNIT=M') = 'TRUE' We use this to get features that are within certain distance from a user defined (clicked) point in our JavaScript app, it has been much faster than using Esri spatial filters. If I use this where clause in the HTML interface of query tasks in services directories, it works for the services published from ArcGIS Server 9.3 and 10.0, but for the service at 10.2 i get: code: 400, message: "Unable to complete operation." I would appreciate any help. Filip.
... View more
03-03-2014
05:10 AM
|
0
|
2
|
3171
|
|
POST
|
Hello, Sometimes with arcpy I feel that to do little you need to write a lot. To make my life easier, I have written and documented a collection of functions, which are available as 'arcapi' on github: https://github.com/NERC-CEH/arcapi You are more than welcome to use it and, even better, contribute - by adding new code or just providing feedback and ideas. To point out only a few functions: 'plot' makes a scatter plot, 'chart' makes a quick map, 'head' prints first rows of a table into the console... the idea is to do a lot with simple function calls. Please see the README.md and arcpy_tutorial.py for more details. I'm sure many of you guys have similar personal libraries, or you wish there was an easy way of coding something. Do you... do you want to share? Filip.
... View more
02-27-2014
01:02 PM
|
0
|
11
|
3269
|
|
POST
|
Hello, If I understand you correctly, you want to use power operation in your formula. In Python, the hat operator (^) means binary XOR, whereas double times (**) is used to indicate power. The ** operator is recognized by Spatial Analyst too, so your desired formula would be: exp2 = str(hydRad1) + ' * ((' + str(flowAcc) + ' * ' + atr(cellSqMilesStr) + ') ** ' + str(hydRad) + ')' This should work if your operands are scalar values or saved raster datasets, not temporary arcpy.Raster objects. Make sure your last operand is correct (is it hydRad or hydRad2 ?). If licensing of the script allows, you should be able to simply change the line in the script and run the tool again. I hope this helps. Filip.
... View more
02-25-2014
12:25 PM
|
0
|
0
|
1957
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-05-2014 04:40 AM | |
| 1 | 02-08-2015 12:49 PM | |
| 1 | 07-20-2014 12:41 PM | |
| 1 | 03-23-2017 01:48 PM | |
| 1 | 08-18-2014 04:14 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|