|
POST
|
Hi Michael, More than 15000 feature classes in a geodatabase is indeed unusual. We could debate about how to avoid that situation in the first place, but that's not the point here. So let's focus on your question. Let's assume that all your feature classes have the same attributes and that they are stored like this: c:/my.gdb/fc1
c:/my.gdb/fc2
...
c:/my.gdb/fc15000
... I would use the following code to merge attributes of all your feature classes into a csv file and then I'd try to open the csv file in Excel. import arcpy
output_file = r'c:\my.csv'
arcpy.env.workspace = r'c:\my.gdb'
feature_classes = arcpy.ListFeatureClasses()
first_fc = feature_classes[0]
fieldnames = [f.name for f in arcpy.ListFields(first_fc) if f.type.lower() != 'geometry']
delimiter = ','
with open(output_file, 'w') as fl:
# write header
fl.write(delimiter.join(fieldnames) + "\n")
# append attributes from each feature class
for fc in feature_classes:
with arcpy.da.SearchCursor(fc, fieldnames) as sc:
for row in sc:
fl.write(delimiter.join(map(str, row)) + '\n')
del row
del sc
If your attributes include some complicated strings or datetime objects, you will be in for a bit of headache with resolving those but the concept is there. Perhaps using tab ('\t') instead of a comma as a delimiter would help with that. I wonder how long is it all going to take. Especially the ListFeatureClasses function call can take a while with that many feature classes. Filip.
... View more
03-02-2017
02:30 PM
|
2
|
20
|
2590
|
|
POST
|
Hi Otto, If I understand you correctly, your problem is that my example above uses web mercator units but you need to define the coordinates in some more meaningful units like meters or feet. Well, doing that can be a little complicated. Projection of the map you are drawing on plays an important role, which I simplify in my explanation below. If your map is in a projection that uses meters or feet, then the job is easy. Simpy define the polygon in the native units of the projection and it will draw correctly. It is more complicated if your map uses a projection like web mercator (where ground distance of a 1 cm long line on the map varies with location on the map and direction of measurement). I think the way to go is to define your polygon is some local projected coordinate system with meters or feet, then project that polygon to the projection of the map, and finally draw this projected polygon on the map. That is the short story. This example of projecting a point can help you (https://developers.arcgis.com/javascript/3/jssamples/util_project.html). Note that it uses ArcGIS Geometry service in the background. If you can't or don't want to use such service, the proj4js (http://proj4js.org/) library may be a good alternative. Filip.
... View more
03-02-2017
02:01 PM
|
0
|
0
|
2585
|
|
POST
|
Hello everyone, I have a time aware map service which is based on a polygon feature class and a stand alone table with the time series data joined to the polygons on a polygon ID field. It is the situation described as Temporal data in separate tables. The service has been working fine but now I need to append new time series data every month. What is the best way to do this? I need to minimise manual interventions so I wonder if it is possible to insert the new data through the RESTful API. I am concerned that the service will not pick it up automatically because they will be out of the date range defined in the map document. I also suspect that some columns in the time series table would need re-indexing and I am afraid I can't do that while the service is running. Any suggestions welcome. Filip.
... View more
01-06-2017
08:20 AM
|
0
|
0
|
1140
|
|
POST
|
Hi, Hmmm, strange. A few things I can think of: Make sure that in_points actually has the sort_field. For example shapefiles usually don't have OBJECTID. Try to modify the expression to w_clause = '%s < %s' % (sort_field, i + 1) I hope you'll find where the problem is. F.
... View more
01-06-2017
08:00 AM
|
0
|
2
|
1200
|
|
POST
|
HI Dan, that's a good tip but the inconsistency occurs even if everything is just in shapefiles. I'll try to find somebody in my organization who can open Esri Support cases. Cheers, Filip.
... View more
01-06-2017
05:55 AM
|
0
|
1
|
1305
|
|
POST
|
Hi everyone, I found an inconsistency between arcpy in Python 2.7 and in Python 3.4 (ArcGIS 10.4.1 and ArcGIS Pro 1.3.1 Patch 1). The task is simple. Take an input feature class and a zone feature class, clip the input FC using the zone FC to produce a clipped FC. Then, use the statistics tool to summarize areas (or whatever) by a category field in the clipped FC. The inconsistency occurs when the the zone feature(s) does not intersect the input feature(s): In Python 2.7, result of the clip tool is an empty feature class with all the columns defined as if there was a feature. Warning 000117 ('empty output generated') is issued but the output feature class does exist. The statistics tool produces an empty output table with the expected fields included. As far as I know, this has been the usual behaviour and that's what my scripts expected. In Python 3.4, result of the clip tool does not produce any output. Warning 000117 is issued but the output feature class does not exist. Calling .getOutput(0) on the clip result object returns the path where the feature class should be, but it is not actually there. Consequently, the statistics tool fails because it requires the result of the clip tool to exist. I need my script to work in both pythons and empty results is a valuable result too. I dealt with it by checking whether the warning was issued. In my case, the task was inside a for-loop and I could simply skip to the next iteration (using the 'continue' statement) when the warning was raised. The code snippet below shows how one can check if the warning was issued and to act accordingly. import arcpy
geology = r'C:\temp\geology.shp'
catchment = r'C:\temp\catchment.shp'
arcpy.env.workspace = r'C:\temp\wdb.gdb'
stats_table = None
clipped = arcpy.analysis.Clip(geology, catchment, 'clppd')
warnings = str(clipped.getMessages(1)).lower()
if 'empty output generated' in warnings:
pass
else:
clipped_fc = clipped.getOutput(0)
stats = arcpy.analysis.Statistics(clipped_fc, 'outtbl', [["Shape_Area", "SUM"]], "LEX")
stats_table = stats.getOutput(0)
The same thing happened when I tried it in ArcGIS Pro user interface so it is probably not a Python problem, but I needed to solve it in Python. I hope this will help someone or that someone will tell me if there is a better way to deal with it. Cheers, Filip.
... View more
01-04-2017
03:51 AM
|
0
|
4
|
2305
|
|
POST
|
Hello, I have encountered two problems when working with script tools in ArcGIS 10.4.1.5686: I added a script tool to a toolbox and define an input parameter of type FeatureLayer. I then opened the tool in ArcMap and dragged one of my layers from the table of contents into the parameter input box. An error sign appeared by the tool parameter saying "Dataset soandso does not exist or is not supported", which is not true. It seems the feature layer parameter behaves as a an input box for type FeatureClass. Another problem was with an output parameter. I created an output parameter of type FeatureClass and set its direction to "Output". When I run the tool, the output was produced but it is not added to the map document (Add output of geoprocessing operations to display is checked) and the result object suggests the output is a table and not a feature class. I can see the resulting feature class in catalog window OK. Have you experienced anything like this? Below is preview of result and the script. import arcpy
def copy_feature_layer_as_feature_class(in_fclr, out_fc):
out = arcpy.management.CopyFeatures(in_fclr, out_fc).getOutput(0)
return out
if __name__ == "__main__":
in_feature_layer = arcpy.GetParameter(0)
out_feature_class = arcpy.GetParameter(1)
fc_copy = copy_feature_layer_as_feature_class(in_feature_layer, out_feature_class)
arcpy.SetParameter(1, fc_copy)
... View more
09-30-2016
08:48 AM
|
0
|
0
|
794
|
|
POST
|
Hello, I have been setting os.environ["TMP"] and os.environ["TEMP"] to unique folders while multiprocessing for some time now and it worked until now. Now I have some code which keeps using the TMP as defined in "User defined variables" in computer properties. The script is too long and too secret to be presented here but I've been through it many times and could not find anything that should cause a problem. I wrote a function to dump the os environ variables, workspace, scratch workspace, scratch folder, and scratch gdb to a file and I used this function in several places in the script. Each dump indicates that these variables are set as I intended, i.e. to the unique folders or geodatabases. When I run the script however, many things are written into the TMP folder defined in "User defined variables" and not to the unique folders. I tried to troubleshoot it for several days but to this time I am not entirely sure why is this happening. However, based on what I have seen, I believe that setting os.environ["TMP"] and os.environ["TEMP"], workspace and scratch workspace to unique folders or geodatabases is necessary, but it is not always enough (in many cases workspace and scratch workspace can point to the same folder or geodatabase). It seems that the crashing I've experienced is caused by spatial analyst tools that write temporary data to represent Raster objects into the temp folder as ESRI Grid (as mentioned in some previous posts). Unless the Raster objects are explicitly saved to a unique workspace or with a unique name, ArcGIS will likely crash. Therefore, it really depends how the functions your master scripts calls and any deeper functions are written. What I ended up doing in my scripts is something like: ...
shrunk_raster = arcpy.sa.Shrink(a_raster)
shrunk_raster.save(os.path.join(wd, 'shrunk')) # wd is a unique workspace for the process, consider using arcpy.CreateScratchName
... The problem is that now I have to pass the unique workspace wd down to every function I call and some function may not allow that kind of parameter. The bottom line is that the crashing would not occur if the deeper functions respected the TMP and TEMP variables in os.environ. Do you have any idea why the os.environ is not honoured? Here is what remained in the TMP folder defined in computer properties once the whole process was over. The CitrixLogs folder is probably not from ArcGIS. Filip.
... View more
09-20-2016
09:15 AM
|
0
|
1
|
2591
|
|
DOC
|
Hi Clinton, thanks for looking into this. In my [arcgispro-py3] environment, 'conda remove qt -y' went fine but then 'conda install qt=4.8.7=vc_10_4 -y' appears to have removed Python 3.4.4-4 and I had to 'conda install python=3.4.4' before I could run python again. When I now run 'spyder' or 'spyder --new-instance', a message is printed in the command line saying 'spyder failed to create process'. I've resorted to writing my code with Python 2.7 and PyScripter against smaller data and ArcGIS for Desktop and then executing it from the ArcGIS Pro Python Command Prompt. Filip. https://getsentry.com/welcome/
... View more
08-11-2016
09:14 AM
|
0
|
0
|
33523
|
|
POST
|
Hi, I tried this in ArcGIS Pro 1.3 with Python 3.4.4 and it behaves well. The key thing is to delete the reference to the layer object when you are done with it ('del lr')! So the right way to create and delete a layer is in_fc, w =r'C:\temp\fc.shp', "FID < 3"
lr = arcpy.management.MakeFeatureLayer(in_fc, 'lr1', w).getOutput(0)
arcpy.management.Delete(lr)
del lr Alternatively, wrapping the part of your where the layer is created, used, and then delted in a function *should* also resolve the issue because (as far as I know) the reference to the layer object *should* be garbage collected by Python when the function finishes. The code below shows more details. It creates a layer, deletes the layer, then it creates and deltes the layer again. You would not do this in practice but it's important to be able to copletely delete layers in Python scripts (e.g. when using arcpy.management.SelectLayerByLocation in a loop). The bottom line is, use the 'del' statement. import arcpy
in_fc=r'C:\temp\fc.shp'
w = "{0} < 3".format(arcpy.Describe(in_fc).OIDFieldName)
lrname = 'lr1'
# create a layer
lr = arcpy.management.MakeFeatureLayer(in_fc, lrname, w).getOutput(0)
print(arcpy.Exists(lr)) # True
print(arcpy.Exists(lrname)) # True
print(type(lr)) # <class 'arcpy._mp.Layer'>
# delete the layer
arcpy.management.Delete(lr)
print(arcpy.Exists(lr)) # True
print(arcpy.Exists(lrname)) # True
del lr
print(arcpy.Exists(lrname)) # False
#print(arcpy.Exists(lr)) # we deleted variable lr using 'del lr' so we can't refer to it
# create and delete the layer again
lr = arcpy.management.MakeFeatureLayer(in_fc, lrname, w).getOutput(0)
print(arcpy.Exists(lrname)) # True
print(arcpy.management.GetCount(lrname).getOutput(0)) # 3
arcpy.management.Delete(lr)
del lr Filip.
... View more
08-05-2016
01:29 AM
|
0
|
0
|
2096
|
|
DOC
|
Hi Shaun, This was my conda info as of this morning. I then tried a few experiments along what is suggested in Setting up Anaconda, PySAL with ArcGIS Python environment | LidarBlog.com When I created a new python 3.4 environment with spyder, I could not run spyder either. I had to 'conda remove qt --name py34' and 'conda install qt=4.8.7=vc10_4' as indicated at Spyder crashes at startup in new conda environment python 3.4 on Windows 8.1 x64 · Issue #2858 · spyder-ide/spyder Then I was able to run spyder. I copied the [arcgispro-py3] enviornment as [arcpro] environment and did 'conda remove qt --name py34' and 'conda install qt=4.8.7=vc10_4' there. That allowed me to open spyder, import arcpy, and run arcpy.Describe on a shapefile. When I tried to run any geoprocessing tool, python crashed again saying "python.exe has stopped working". It would be good to hear if (and how many) other people managed to install and run spyder just by running 'conda insall spyder' in the [arcgispro-py3] environment when they first installed ArcPro 1.3. Filip.
... View more
07-27-2016
08:44 AM
|
0
|
0
|
33523
|
|
DOC
|
Hi Dan, I did read through it. I think I understand what you did there, but I get the same error when I try to edit a script from ArcGIS Pro directly. Still no joy. F.
... View more
07-26-2016
09:10 AM
|
0
|
0
|
33523
|
|
DOC
|
Hi Shaun, thanks for the link but unfortunately none of the steps resolved the problem. I noticed I can't run Spyder just by typing 'Spyder' into a command line (command not recognized), I have to be in the Python Command Prompt that comes with ArcGIS Pro with [arcgispro-py3] environment enabled. It that normal? Also, the only ".spyder" directory I found was 'C:\Users\<myusername>\.spyder2-py3'. Deleting it did not help. Does anyone else have the same problem? Filip.
... View more
07-26-2016
04:17 AM
|
0
|
0
|
33523
|
|
DOC
|
Hi all, I just installed ArcGIS Pro 1.3 and then spyder using the instructions in the original article from David Wynne ('conda install spyder'). The installation seems to have gone without any problem but I cannot open spyder (neither from the Start menu nor from an interactive command line with the arcgispro-py3 environment, neither as admin nor as a normal user). When I try to start spyder, the spyder splashscreen shows up and when the status bar gets to "Loading IPython console...", an error message appears saying "python.exe has stopped working". The installed versions are conda (4.0.6), spyder (2.3.9), qtconsole (4.2.1), jupyter (1.0.0). Here is how my start menu looks like Do you know what's going on? How to fix this? Filip.
... View more
07-25-2016
03:50 AM
|
0
|
0
|
33523
|
|
POST
|
Thank you, calling pool.close() and pool.join() did the trick. F.
... View more
03-30-2016
01:59 PM
|
0
|
0
|
7832
|
| 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
|