POST
|
Sorry, I should have mentioned that I tried the "verify" functionality, and it gave no warnings or errors.
... View more
04-06-2012
11:05 AM
|
0
|
0
|
284
|
POST
|
On the shapefile, the field is of type TEXT, on the SQL Server table, the field is of type nvarchar(154)
... View more
04-06-2012
06:54 AM
|
0
|
0
|
284
|
POST
|
Hi, I'm using ArcMap 10.0. I'm trying to inner join (with the join tool) a shape file with a table from an SQL Server data connection. It fails with 0 records. Howerver, when I export the table to a .DBF file, then do the same join, it works as expected!? Any ideas? The data appears unchanged before and after the export. It's something under the hood, I expect... Thanks, Dustin
... View more
04-04-2012
02:14 PM
|
0
|
6
|
559
|
POST
|
To clarify, the polygon shown in my first post is correct. I'm just wondering why I have to use the method that I did to create it, and why the method elaborated on in your example does not work and results in a null polygon.
... View more
10-07-2011
11:24 AM
|
0
|
0
|
345
|
POST
|
Is suspect that your latter fails since you are passing an array and not an array of point objects to the polygon class. follow the example in the help file http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Polygon/000v000000n1000000/ Hi, My method is functionally equivalent to the example described in this link (in the sense that an arcpy.Polygon is created with an arcpy.Array filled with the exact same data, in both my example and the example you linked to). To double check, I used the example script, except with my data. It still silently generates a null (empty) polygon:
import arcpy
# A list of features and coordinate pairs
coordList = [[[-88.680463013034853, 38.152519617763254], [-88.680463013034853, 38.15068957953018], [-88.678182297717754, 38.15068957953018], [-88.678182297717754, 38.152519617763254]]]
# Create empty Point and Array objects
#
point = arcpy.Point()
array = arcpy.Array()
# A list that will hold each of the Polygon objects
#
featureList = []
for feature in coordList:
# For each coordinate pair, set the x,y properties and add to the
# Array object.
#
for coordPair in feature:
point.X = coordPair[0]
point.Y = coordPair[1]
array.add(point)
# Add the first point of the array in to close off the polygon
#
array.add(array.getObject(0))
# Create a Polygon object based on the array of points
#
polygon = arcpy.Polygon(array)
# Clear the array for future use
#
array.removeAll()
# Append to the list of Polygon objects
#
featureList.append(polygon)
# Create a copy of the Polygon objects, by using featureList as input to
# the CopyFeatures tool.
#
arcpy.CopyFeatures_management(featureList, "c:/geometry/polygons.shp")
... View more
10-07-2011
11:18 AM
|
0
|
0
|
345
|
POST
|
Is suspect that your latter fails since you are passing an array and not an array of point objects to the polygon class. follow the example in the help file http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Polygon/000v000000n1000000/ and in the previous discussion on creating polygons with donuts in them http://forums.arcgis.com/threads/18985-Bug-Creating-polygons-with-holes-using-Arcpy?p=61005&posted=1#post61005 Hi, I may be missing something, but as far as I can tell I am very clearly passing an arcpy.Array filled with arcpy.Point objects to the arcpy.Polygon factory:
array = arcpy.Array()
point = arcpy.Point()
# Create a list to store the features
features = []
# Read the coordinates
for part in coordList:
for coordPair in part:
point.X = coordPair[0]
point.Y = coordPair[1]
array.add(point)
print "points added to array: "
for point in array:
print point.X,point.Y
print "points in polygon: "
polygon = arcpy.Polygon( array ) Is this not actually passing an array of point objects to the polygon object? Thanks for your time, Dustin
... View more
10-07-2011
11:09 AM
|
0
|
0
|
345
|
POST
|
Hi, I'm continuing to have problems creating polygons programmatically. For example: (This polygon is correct) was created with this script: #interior
coordList = [[[-88.680463013034853, 38.152519617763254], [-88.680463013034853, 38.15068957953018], [-88.678182297717754, 38.15068957953018], [-88.678182297717754, 38.152519617763254], [-88.680463013034853, 38.152519617763254]]]
def main():
outputShapeDir = r"c:\temp"
outputShapeFile = r"test.shp"
prjFile = os.path.join(arcpy.GetInstallInfo()["InstallDir"],
"Coordinate Systems/Geographic Coordinate Systems/North America/NAD 1983.prj")
spatialRef = arcpy.SpatialReference(prjFile)
newFC = arcpy.CreateFeatureclass_management( outputShapeDir, outputShapeFile, "POLYGON", "", "", "", spatialRef )
cur = arcpy.InsertCursor(newFC)
array = arcpy.Array()
point = arcpy.Point()
# Create a list to store the features
features = []
# Read the coordinates
for part in coordList:
for coordPair in part:
point.X = coordPair[0]
point.Y = coordPair[1]
array.add(point)
print "points added to array: "
for point in array:
print point.X,point.Y
#print "points in polygon: "
#polygon = arcpy.Polygon( array )
#for part in polygon:
# for point in part:
# print point.X,point.Y
feat = cur.newRow()
feat.shape = array
cur.insertRow( feat )
if __name__ == '__main__':
import arcpy
import os
arcpy.env.overwriteOutput = True
main() Note that I never created an arcpy.Polygon, i simply assigned my arcpy.Array, filled with arcpy.Points, to the feature's "shape" property. with this printed output: points added to array:
-88.680463013 38.1525196178
-88.680463013 38.1506895795
-88.6781822977 38.1506895795
-88.6781822977 38.1525196178
-88.680463013 38.1525196178 However, a null (empty) geometry was produced with the following code. Note the very minor difference of creating an arcpy.Polygon with "array" and assigning that result to "feat.shape" instead of assigning "array" directly (which is actually how the arcpy documentation shows how to write polygons, by the way). coordList = [[[-88.680463013034853, 38.152519617763254], [-88.680463013034853, 38.15068957953018], [-88.678182297717754, 38.15068957953018], [-88.678182297717754, 38.152519617763254], [-88.680463013034853, 38.152519617763254]]]
def main():
outputShapeDir = r"c:\temp"
outputShapeFile = r"test.shp"
prjFile = os.path.join(arcpy.GetInstallInfo()["InstallDir"],
"Coordinate Systems/Geographic Coordinate Systems/North America/NAD 1983.prj")
spatialRef = arcpy.SpatialReference(prjFile)
newFC = arcpy.CreateFeatureclass_management( outputShapeDir, outputShapeFile, "POLYGON", "", "", "", spatialRef )
cur = arcpy.InsertCursor(newFC)
array = arcpy.Array()
point = arcpy.Point()
# Create a list to store the features
features = []
# Read the coordinates
for part in coordList:
for coordPair in part:
point.X = coordPair[0]
point.Y = coordPair[1]
array.add(point)
print "points added to array: "
for point in array:
print point.X,point.Y
print "points in polygon: "
polygon = arcpy.Polygon( array )
for part in polygon:
for point in part:
print point.X,point.Y
feat = cur.newRow()
feat.shape = polygon
cur.insertRow( feat )
if __name__ == '__main__':
import arcpy
import os
arcpy.env.overwriteOutput = True
main() Here is the print output: points added to array:
-88.680463013 38.1525196178
-88.680463013 38.1506895795
-88.6781822977 38.1506895795
-88.6781822977 38.1525196178
-88.680463013 38.1525196178
points in polygon: As you can see, after the arcpy.Polygon, "polygon", is created with the contents of "array", the resultant polygon is empty. Why? No exceptions are thrown, and the program completes normally. What is the difference, functionally, in creating geometry between these two methods? Thanks for any help, Dustin
... View more
10-07-2011
10:42 AM
|
0
|
4
|
1882
|
POST
|
Thank you very much for the reply. Unfortunately your script also produces incorrect (but close) results: Additionally, your method appears to be functionally equivalent to the last method that I posted. You say: It appears that your error is to add a null point at the end of a part, rather than making the hole within the same part. Likewise adding a null point between parts would not make a donut, just a null part which would be erases by the validator. If you'll look closely at my code, you'll see that I only ever add a single part to "array", putting a null Point between the points that describe exterior and the points that describe the interior (all in the same part). array = arcpy.Array()
point = arcpy.Point()
# Create a list to store the features
features = []
# Read the coordinates
for part in gjPolygonWithHole["coordinates"]:
for coordPair in part:
point.X = coordPair[0]
point.Y = coordPair[1]
array.add(point)
null_point = arcpy.Point()
array.add(null_point)
feat = cur.newRow()
feat.shape = arcpy.Polygon( array )
cur.insertRow( feat ) Unless I am mistaken, adding multiple parts to a polygon would involve something like:
point = arcpy.Point()
polygonArray = arcpy.Array()
partArray = arcpy.Array()
for part in coordinateList:
for coordPair in part:
point.X = coordPair[0]
point.Y = coordPair[1]
partArray.add(point)
#add the null point
partArray.add( arcpy.Point() )
polygonArray.add(partArray)
partArray.removeAll()
newMultiPartPolygon = arcpy.Polygon( polygonArray )
polygonArray.removeAll()
Thanks for your time, Dustin
... View more
10-07-2011
07:52 AM
|
0
|
0
|
311
|
POST
|
I tried this method to create a polygon with holes, and nearly succeeded. Take a look at this thread for details. Any help explaining why the method described here fails in my case would be appreciated. Thanks, Dustin
... View more
10-06-2011
01:03 PM
|
0
|
0
|
2374
|
POST
|
Hi, I was searching for a way to programmatically create a polygon with a hole, as there isn't any obvious way of doing this in the documentation, I started fumbling around on my own. I came up with this test script: gjPolygonWithHole = {
"type": "Polygon",
"coordinates": [
[[-88.684979400000032, 38.154361399999985], [-88.666690199999962, 38.154329800000042], [-88.67131005539963, 38.154337782166039], [-88.675899944207302, 38.154345712555887], [-88.675899944207302, 38.150691003182175], [-88.67131005539963, 38.150691003182175], [-88.67131005539963, 38.147037172952786], [-88.675899944207302, 38.147037172952786], [-88.685066075460313, 38.147037172952786], [-88.684979400000032, 38.154361399999985]],
[[-88.680463013034853, 38.152519617763254], [-88.680463013034853, 38.15068957953018], [-88.678182297717754, 38.15068957953018], [-88.678182297717754, 38.152519617763254], [-88.680463013034853, 38.152519617763254]]]
}
def main():
outputShapeDir = r"c:\temp"
outputShapeFile = r"test.shp"
spatialRef = r'X:\Nadel&Gussman\McLeansboro\Sections.prj'
newFC = arcpy.CreateFeatureclass_management( outputShapeDir, outputShapeFile, "POLYGON", "", "", "", spatialRef )
cur = arcpy.InsertCursor(newFC)
array = arcpy.Array()
point = arcpy.Point()
# Create a list to store the features
features = []
# Read the coordinates
for part in gjPolygonWithHole["coordinates"]:
for coordPair in part:
point.X = coordPair[0]
point.Y = coordPair[1]
array.add(point)
feat = cur.newRow()
feat.shape = array
cur.insertRow( feat )
if __name__ == '__main__':
import arcpy
arcpy.env.overwriteOutput = True
main() Amazingly, it works (I'm not really sure how, since I don't do anything to separate the interior from the exterior, other than suddenly switch winding order): Unfortunately, this doesn't work in all polygon-with-a-hole cases that I am working with. So...I noticed the seemingly useful "AsShape" functionality here. Specifically, (notice the AsShape example on doing just this at the bottom of the page i linked). I put together a little sample script to test this: gjPolygonWithHole = {
"type": "Polygon",
"coordinates": [
[[-88.684979400000032, 38.154361399999985], [-88.666690199999962, 38.154329800000042], [-88.67131005539963, 38.154337782166039], [-88.675899944207302, 38.154345712555887], [-88.675899944207302, 38.150691003182175], [-88.67131005539963, 38.150691003182175], [-88.67131005539963, 38.147037172952786], [-88.675899944207302, 38.147037172952786], [-88.685066075460313, 38.147037172952786], [-88.684979400000032, 38.154361399999985]],
[[-88.680463013034853, 38.152519617763254], [-88.680463013034853, 38.15068957953018], [-88.678182297717754, 38.15068957953018], [-88.678182297717754, 38.152519617763254], [-88.680463013034853, 38.152519617763254]]]
}
def main():
outputShapeDir = r"c:\temp"
outputShapeFile = r"test.shp"
spatialRef = r'X:\Nadel&Gussman\McLeansboro\Sections.prj'
newFC = arcpy.CreateFeatureclass_management( outputShapeDir, outputShapeFile, "POLYGON", "", "", "", spatialRef )
cur = arcpy.InsertCursor(newFC)
feat = cur.newRow()
feat.shape = arcpy.AsShape( gjPolygonWithHole )
cur.insertRow( feat )
if __name__ == '__main__':
import arcpy
arcpy.env.overwriteOutput = True
main() FAILURE: The hole is completely ignored. Any clue as to why? Regarding holes, I found this thread, and adapted their method to my test script + data. It almost works: Here's my example code: gjPolygonWithHole = {
"type": "Polygon",
"coordinates": [
[[-88.684979400000032, 38.154361399999985], [-88.666690199999962, 38.154329800000042], [-88.67131005539963, 38.154337782166039], [-88.675899944207302, 38.154345712555887], [-88.675899944207302, 38.150691003182175], [-88.67131005539963, 38.150691003182175], [-88.67131005539963, 38.147037172952786], [-88.675899944207302, 38.147037172952786], [-88.685066075460313, 38.147037172952786], [-88.684979400000032, 38.154361399999985]],
[[-88.680463013034853, 38.152519617763254], [-88.680463013034853, 38.15068957953018], [-88.678182297717754, 38.15068957953018], [-88.678182297717754, 38.152519617763254], [-88.680463013034853, 38.152519617763254]]]
}
def main():
outputShapeDir = r"c:\temp"
outputShapeFile = r"test.shp"
spatialRef = r'X:\Nadel&Gussman\McLeansboro\Sections.prj'
newFC = arcpy.CreateFeatureclass_management( outputShapeDir, outputShapeFile, "POLYGON", "", "", "", spatialRef )
cur = arcpy.InsertCursor(newFC)
array = arcpy.Array()
point = arcpy.Point()
# Create a list to store the features
features = []
# Read the coordinates
for part in gjPolygonWithHole["coordinates"]:
for coordPair in part:
point.X = coordPair[0]
point.Y = coordPair[1]
array.add(point)
null_point = arcpy.Point()
array.add(null_point)
feat = cur.newRow()
feat.shape = arcpy.Polygon( array )
cur.insertRow( feat )
if __name__ == '__main__':
import arcpy
arcpy.env.overwriteOutput = True
main() Any ideas why this doesn't work? Why is creating geometry such a hassle with arcpy? Why do some methods work and some do not? Most likely I'm missing something obvious... Thanks, Dustin
... View more
10-06-2011
12:58 PM
|
0
|
2
|
2551
|
POST
|
I was having a problem creating certain polygons programmatically, so I put together this simple example to illustrate the issue. The following code works as expected (creates a simple square):
outputFeatureClass = r"c:\temp\test.shp"
coordList = [[0, 0],
[0, -0.01],
[.01, -.01],
[.01, 0],
[0, 0]]
def main():
array = arcpy.Array()
point = arcpy.Point()
# Create a list to store the features
features = []
# Read the coordinates
for coordPair in coordList:
point.X = coordPair[0]
point.Y = coordPair[1]
array.add(point)
polygon = arcpy.Polygon(array)
# Append to the feature list
features.append(polygon)
# Copy the features to an output feature class
arcpy.CopyFeatures_management(features, outputFeatureClass)
if __name__ == '__main__':
import arcpy
arcpy.env.overwriteOutput = True
main()
However, if i change coordList to:
coordList = [[0, 0],
[0, -0.001],
[0.001, -0.001],
[0.001, 0],
[0, 0]] The script completes successfully, but the resulting geometry is a "null" shape, according to the check geometry tool. My guess is that the vertices are all getting merged at some point? If so, why, and how can i prevent it? Thanks, Dustin
... View more
09-29-2011
02:12 PM
|
0
|
1
|
301
|
POST
|
I'm trying to simply do: updateRows = arcpy.UpdateCursor("Database Connections/Marshall_East.odc/LeaseSchedule") which is failing with the following RuntimeError: "Handling run-time error: ERROR 999999: Error executing function. An underlying database error occurred. [LeaseSchedule] Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done." Is there any way to "Check each OLE DB status value" from within the arcpy environment? Creating a SearchCursor on the same DB, and iterating over the rows works fine. Any clues would be appreciated. Thanks, Dustin
... View more
08-30-2011
11:10 AM
|
0
|
1
|
1610
|
POST
|
setValue only works with insertcursor or updatecursors Thank you! I knew I was overlooking something obvious...I looked at this help page multiple times, but overlooked the different cursor types!
... View more
07-29-2011
10:53 AM
|
0
|
0
|
156
|
POST
|
Hi, I'm probably overlooking something obvious, but i'm unable to set a value on a field of a feature class. Here is a short example to show what I am doing.
import arcpy
from arcpy import env
env.workspace = r"X:\temp"
fc = "temp.shp"
desc = arcpy.Describe( fc )
print 'Fields: '
for field in desc.fields:
print 'Name: ', field.name, 'Type: ', field.type, 'Length: ', repr(field.length)
rows = arcpy.SearchCursor( fc )
for row in rows:
row.setValue("S_T_R", "test")
Here is the output: Fields: Name: FID Type: OID Length: 4 Name: Shape Type: Geometry Length: 0 Name: TOWNSHIP_N Type: Double Length: 11 Name: TOWNSHIP_D Type: String Length: 1 Name: RANGE_NUM Type: Double Length: 11 Name: RANGE_DIR Type: String Length: 1 Name: RECORD_NUM Type: String Length: 3 Name: SECTION Type: Double Length: 11 Name: ID_FIELD Type: String Length: 9 Name: S_T_R Type: String Length: 12 Traceback (most recent call last): File "C:/code/scripts/GIS/addS_T_R.py", line 20, in <module> row.setValue("S_T_R", "test") File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\arcobjects.py", line 940, in setValue return convertArcObjectToPythonObject(self._arc_object.SetValue(*gp_fixargs(args))) RuntimeError: ERROR 999999: Error executing function. Thanks for any pointers. Dustin
... View more
07-29-2011
10:06 AM
|
0
|
2
|
518
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|