|
POST
|
The gist of what you need is: outFC = #path to shapefile, ending in .shp
coords = [[0.0, 0.0],[0.0, 1.0],[1.0, 1.0],[1.0, 0.0]]
arr = arcpy.Array([arcpy.Point(*coord) for coord in coords])
pn = arcpy.Polygon(arr)
arcpy.CopyFeatures_management(pn, outFC)
... View more
12-14-2014
08:20 AM
|
1
|
3
|
1984
|
|
POST
|
(When I first wrote this reply there was a code snippet that has since been removed, which is unfortunate because it is easier for others to comment on code and it demonstrates previous efforts to solve the problem. Although my comments might not make sense to other readers, the OP should understand them.) Reviewing ArcGIS Help for Create Feature Class (Data Management), especially the code samples, would be helpful. With the current approach you are taking, the Copy Features (Data Management) tool is more likely what you will need.
... View more
12-14-2014
07:26 AM
|
0
|
4
|
1984
|
|
POST
|
Beyond the issue identified by Dan Patterson, you have two additional problems. First, the SQL "IN" operator requires the set of values to be enclosed in parentheses, e.g., expression IN (value1, value2, value3, ...). Second, the ExtractByAttributes where_clause is a string-based SQL expression, and you are passing a reference to a python object instead of an actual string-based list. Assuming values is a Python list containing numbers you want to check for, line 30 would have to be rewritten as: query = "Value IN ({})".format(str(values).strip('[]'))
... View more
12-11-2014
01:51 PM
|
2
|
2
|
1927
|
|
POST
|
Richie Carmichael, I don't recall seeing any comments or documentation about Diagrammer being retired at 10.2. Did I miss it somewhere?
... View more
12-11-2014
01:03 PM
|
1
|
0
|
11453
|
|
POST
|
A quick code example.... There are various ways to add fields to structured numpy arrays. Although it might not be the most performant, I typically use a solution proposed by Vebjorn Ljosa on StackExchange: Adding a field to a structured numpy array. def add_field(a, descr):
if a.dtype.fields is None:
raise ValueError, "`A' must be a structured numpy array"
b = numpy.empty(a.shape, dtype=a.dtype.descr + descr)
for name in a.dtype.names:
b[name] = a[name]
return b Although some people suggest using append_fields from numpy.lib.recfunctions, I have run into problems when the appended field will hold subarrays. Using the Code Sample from the NumPyArrayToFeatureClass (arcpy.da) Help page (but dropping the TX spatial references): import numpy
outFC = #Output FS location and name
# Create a numpy array with an id field, and a field with a tuple
# of x,y coordinates
array = numpy.array([(1, (471316.3835861763, 5000448.782036674)),
(2, (470402.49348005146, 5000049.216449278))],
numpy.dtype([('idfield',numpy.int32),('XY', '<f8', 2)]))
# Export the numpy array to a feature class using the XY field to
# represent the output point feature
arcpy.da.NumPyArrayToFeatureClass(array, outFC, ['XY']) yields a feature class with the following table: Using the add_field function above to duplicate the 'XY' field: import numpy
outFC = #Output FS location and name
# Create a numpy array with an id field, and a field with a tuple
# of x,y coordinates
array = numpy.array([(1, (471316.3835861763, 5000448.782036674)),
(2, (470402.49348005146, 5000049.216449278))],
numpy.dtype([('idfield',numpy.int32),('XY', '<f8', 2)]))
# Add new field to duplicate XY field so they show up as attributes
arr = add_field(array, [('XY1', '<f8', 2)])
arr['XY1'] = array['XY']
# Export the numpy array to a feature class using the XY field to
# represent the output point feature
arcpy.da.NumPyArrayToFeatureClass(arr, outFC, ['XY']) yields a feature class with the following table: Unlike the Code Sample, I usually don't store the XY coordinates as a tuple in a numpy structured array because they end up getting stored as subarrays, which I find a bit more cumbersome to work with and not a requirement to use NumPyArrayToFeatureClass.
... View more
12-10-2014
10:06 AM
|
0
|
0
|
2456
|
|
POST
|
From a post 6 months ago in the ArcGIS Beta Community forums: Kent Marten wrote: This is expected as direct read of Excel worksheets (or Named Ranges) as tables is not planned to be supported during the first release of ArcGIS Pro.
... View more
12-09-2014
05:50 PM
|
1
|
2
|
2713
|
|
POST
|
You can take the geoprocessing route as Xander Bakker suggests. If you want a pure Python/NumPy solution, please post a bit more information. You say you are getting a duplicate field error with the array, but what method or function is returning the error? I didn't catch it at first, but your original dtype had a Lat and Lat1 as well as a Long and Long1. Do those represent different lats and longs or duplicates? You mentioned pulling this data from a database through a DSN connection to create the array. Would it work to connect to the table and use the MakeXYEventLayer_management to make an event layer that you can save to disk afterwards.
... View more
12-09-2014
03:45 PM
|
0
|
0
|
2456
|
|
POST
|
By default, or at least in my experience, NumPyArrayToFeatureClass doesn't include the shape fields as attribute fields in the output feature class. If you want LatLong as attributes as well, copy the columns and give the new columns a different name, and either use the new columns or the original as the shape fields with the other set getting incorporated as attributes.
... View more
12-09-2014
08:35 AM
|
1
|
3
|
2456
|
|
POST
|
The Key Error outside of the Try block is the crux of the issue. As far as the interpreter is concerned, there is no key corresponding to the value you are giving it, so it returns a Key Error, i.e., u'B01001e1' is not key, period. At this point, are there any differences in capitalization or white spaces? I don't think it is an text encoding issue. Trying printing your dictionary (print dictflds) and double checking that there is in fact a u'B01001e1' key.
... View more
12-08-2014
12:17 PM
|
0
|
1
|
2483
|
|
POST
|
A few things. What is the error message, specifically? Second, it seems you are naming your dictionary 'dict', which shadows the built-in dict constructor. Although shadowing a built-in doesn't break the code, per se, it does make it more difficult to read and therefore more prone to errors. Third, the code snippet doesn't show the dictionary object being created, is that just handled earlier?
... View more
12-08-2014
11:09 AM
|
0
|
3
|
2483
|
|
DOC
|
Rudy Prosser, thanks for pulling this information together in one place. Although I have been working with geodatabases for years, this compilation of geodatabase-related information will be great to share with others in our organization that are newer to geodatabases. Since 10.3 is right around the corner, get ready to update most of the links!
... View more
12-05-2014
12:52 PM
|
0
|
0
|
3725
|
|
POST
|
Map documents (mxd) are part of ArcGIS Desktop, not ArcGIS Pro. ArcGIS Pro is organized differently and has Project files (aprx), similar to the old ArcView Project files (apr). Once you create a new ArcGIS Pro project, you can import MXDs as maps within the project.
... View more
12-05-2014
12:44 PM
|
3
|
3
|
5178
|
|
POST
|
The functional code for recursively listing feature classes in a geodatabase is provided as ListFeatureClasses example 1 in the help for ListFeatureClasses (arcpy). The topic was also covered in the Recursive list feature classes post at ArcPy Cafe a couple years back. For your situation, I believe the following code will work: import os
ws = #path to gdb
arcpy.env.workspace = ws
for ds in arcpy.ListDatasets(feature_type="Feature"):
for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
arcpy.Rename_management(
os.path.join(ws, ds, fc),
os.path.join(ws, ds, '{}_{}'.format(ds,fc[:-3]))
) The code above will rename what you have already manually renamed.
... View more
12-05-2014
06:37 AM
|
0
|
0
|
1574
|
|
POST
|
I ran this question through Esri Support: BUG-000083762: In each cursor documentation, specify the type of lock being closed and released, as a shared lock is still present in the geodatabase after the 'with' statement executes. I can't say I am surprised, but Esri seems to be calling this a documentation bug and not a software bug, likely because it is much easier to update the documentation to say not all the locks are actually removed.
... View more
12-04-2014
03:21 PM
|
0
|
0
|
2745
|
|
POST
|
Bug BUG-000083762: In each cursor documentation, specify the type of lock being closed and released, as a shared lock is still present in the geodatabase after the 'with' statement executes.
... View more
12-04-2014
03:04 PM
|
0
|
0
|
5003
|
| Title | Kudos | Posted |
|---|---|---|
| 2 | 3 weeks ago | |
| 1 | 4 weeks ago | |
| 1 | 3 weeks ago | |
| 3 | 3 weeks ago | |
| 1 | 05-22-2026 05:27 AM |
| Online Status |
Offline
|
| Date Last Visited |
Thursday
|