|
POST
|
The old example is as simple as it gets. 8-) You need to define a new featureclass that is Z-aware so that you can iterate through the features, parts, vertices to extract the coordinates and then roll back the process to create new features from arrays. If you have x,y,z points then the easiest way would be to use the tool PointsToLine to rebuild a series of lines.
... View more
07-29-2012
09:53 PM
|
0
|
0
|
1298
|
|
POST
|
I assume you are loading a library into a file geodatabase. Forget shapefiles, so last century. But I used to do this, by making up a folder for each tile and have shapefiles there. I now append all the coverages together into a single featureclass for each layer. Here is some old code with the main function included. Key features to note are: A dictionary to rename the coverages to shapefiles, otherwise they are all point, line, polygon. I used a complicated dropfields to remove redundant system fields to get around a bug at the time. You have to be in the workspace to list coverages which appear a featuredatasets to Python. A list is much more flexible to re-run after crashes to redo the load with a smaller list. I accessed the tiles in the library directly. Field names were automatically truncated which may be a problem, you could now use fieldmapping, but not if you are a beginner. Some functions removed to meet posting linecount limit.
# MobileDirectLoad.py
# load coverage tiles
# Kimo Nov 2006
# With simple toolbox
# or just run from PythonWin
#
# load directly from coverages 12 April 2012
# except for parcels which are multipart direct load
# from currentgdb/parcel.gdb
# ArcGIS 9.1
# ArcGIS 9.3+ October 2009
# bugfix 21 Oct 2009 in warning message
# 10.0 with 9.3 gdb format 10 Nov 2011
# 10.0 upgrade
# 14 April 2012
# 19 June 2012 bug fix for ccaddress
import arcpy,sys,os,datetime
# -- functions removed --
#======================== main =============================
start = datetime.datetime.now()
droplst = ["xxx","rings_ok","rings_nok","lpoly#","rpoly#",
"fnode#","tnode#","length","area","perimeter",
"lpoly","rpoly","parcel#","parcel-id","poly#",
"sufi","toc-code","parcel-int",
"total-area","addressp", "pre-dir", "street-name",
"street-type", "suf-dir","name-crs","alt-id",
"$polygonid",
"range_low","range_high","unofficial",
"multi","case1","case2","case3",
"$SCALE","$ANGLE","PAR-ID","OTHR#","OTHR-ID",]
sr = arcpy.SpatialReference()
sr.factoryCode = 2193 # NZTM
sr.create()
arcpy.env.outputCoordinateSystem = sr
try:
gdb = sys.argv[1] # "e:/crs/mobile/mobile.gdb"
repl = sys.argv[2]
arcpy.AddMessage(repl)
if repl.lower() == 'true' :
replace = True
elif not repl.lower() == 'false':
replace = False
except :
gdb = "e:/crs/mobile/mobile.gdb"
replace =False
ws = "e:/lib/nztm/tile"
if not arcpy.Exists(gdb) :
dir = os.path.dirname(gdb)
filegdb = os.path.basename(gdb)
print dir,filegdb
arcpy.management.CreateFileGDB(dir,filegdb,"9.3")
arcpy.env.workspace = ws+"/t1001/data"
dictCov = { "add_all":"address/point",
"emf":"emf/point",
"fename":"fename/point",
"hydro":"hydro/polygon",
"hydrobdy":"hydro/arc",
"lparcel":"lparcel/arc",
"olabel":"olabel/point",
"owner":"owner/point",
"parcel":"parcel/polygon",
"parcelbdy":"parcel/arc",
"perror":"perror/polygon",
"plabel":"plabel/point",
"plan":"plan/point",
"pother":"pother/region.othr",
"strata":"pother/region.othr",
"rail":"rail/arc",
"res":"res/polygon",
"reserve":"res/polygon",
"road":"road/arc",
"shway":"shway/arc",
"surveypt":"surveypt/point",
"title":"title/point",
"titledif":"titledif/point",
"up":"up/point",
"uparcel":"uparcel/point"
}
lstFC = ["add_all","title","fename","road","rail","strata","plabel","olabel","lparcel","up","uparcel","surveypt","plan","perror","reserve","parcelbdy",]
# lstFC = ["title","fename","parcelbdy","road","rail","strata","plabel","olabel","lparcel","up","uparcel","surveypt","plan","perror","reserve"]
# parcel removed because multipart from elsewhere
# lstFC = ["add_all"]
# xlabel removed 13 July 2007
# address renamed because special processing required
for outFCName in lstFC :
cov = dictCov[outFCName]
fds = cov.split("/")[0]
print "Processing",outFCName,cov
arcpy.AddMessage(outFCName)
if not arcpy.Exists(gdb+"/"+outFCName) :
lstSrc = []
# merge the coverages in all the tiles from 1001 - 1012
for ld in range(12) :
tile = "t%d" % (ld + 1001)
srcCov = ws+"/"+tile+"/data/"+cov
if arcpy.Exists(srcCov) :
lstSrc.append(srcCov)
else :
arcpy.AddError(srcCov+'not found')
print srcCov,"NOT FOUND"
# Create FieldMappings object to manage merge output fields
fieldMappings = arcpy.CreateObject("FieldMappings")
# Add all fields from sources
for src in lstSrc:
fieldMappings.addTable(src)
# hide fields
print " removing ",
for fld in [fds+"#",fds+"-ID"] + droplst: #include cov# and cov-id
pos = fieldMappings.findFieldMapIndex(fld.upper())
# print pos,fld
if pos >= 0 :
fieldMappings.removeFieldMap(pos)
print fld.upper(),
print
print " keeping ",
for x in range(fieldMappings.fieldCount):
print fieldMappings.getFieldMap(x).outputField.name,
print
arcpy.Merge_management(lstSrc, gdb+"/"+outFCName,fieldMappings )
print outFCName,"merged"
arcpy.AddMessage(outFCName+" merged")
else :
print "Skipping load of",outFCName
arcpy.AddWarning("Skipping load of "+outFCName)
print "Done", datetime.datetime.now() - start
arcpy.AddMessage("Done")
... View more
07-29-2012
09:21 PM
|
0
|
0
|
1018
|
|
POST
|
It is a bit hard to give advice without seeing the script. You should add some print statements and tests to see if you are getting what you expect. Usually the problem is that I have no data on the subsequent pass because of an unexpected data value. If I have NULL values or empty featureclasses I get all sorts of strange errors that are meaningless. I moved to a python module matplotlib http://matplotlib.sourceforge.net/for programming graphs because it was much more flexible. I know you want to only use geoprocessing tools but this was my resort, after all the ArcGIS graphing tools are an external package themselves with a thin wrapper of limited functionality.
... View more
07-29-2012
03:04 PM
|
0
|
0
|
645
|
|
POST
|
Esri uses Pythonwin for training. It is a wrapper around IDLE to make it much nicer than the raw IDLE interface for Windows. Free. Recommended. It is called win32all because it has additional functions to interface with the win32 API. Since Arc Desktop is only on Windows this is a useful addition. http://sourceforge.net/projects/pywin32/. I cannot see how anyone would be developing geoprocessing scripts in Linux. Since geoprocessing scripts are so simple (in python terms) a more complex debugging environment such as Wing or Eclipse is not justified. Most of your problems will be in the geoprocessing tools where single step python tools will be useless. I keep trying the other development environments but always come back to Pythonwin. Pythonwin allows you to enter test parameters which makes debugging scripts easier, simulating the dialog entries. Intellisense (command completion) for tools is supported if you import arcpy in the interactive window. This is almost essential now that geoprocessing tools are case sensitive.
... View more
07-29-2012
02:44 PM
|
0
|
0
|
1496
|
|
POST
|
I found that the graphs work well for simple tasks but are hard to customise or generalise. For more flexibility you might like to try a python module matplotlib http://matplotlib.sourceforge.net/. You do have to move the data to a numpy array, but there are tools for that.
... View more
07-29-2012
02:31 PM
|
0
|
0
|
993
|
|
POST
|
The help for addins has exactly this fishnet as an example. I did manage to get it to work, but.... Addins are quite complex and difficult to debug. For each fix you have to recompile the addin, copy the files to the addins directory and restart ArcGIS every time because there is no equivalent to the python 'reload' command. If you only want to get a couple of points, then do this at the start using the featureset type in the dialog for a normal tool. This is a very flexible input method that can take any feature type (point, line, polygon) to generate a temporary featureclass that is delivered as a parameter to use. You can also add a geoprocessing tool to a menu with a simple icon. These abilities have been available since 9.3 but has not been properly publicised. Popping up a coordinate in a box can be done in python using the windows message box. import win32ui,win32con
for i in range(32) :
ok = win32ui.MessageBox("type"+str(i),"Message Title",i)
print "Form type",i,"Button",ok
... View more
07-29-2012
02:07 PM
|
0
|
0
|
6533
|
|
POST
|
Maybe it is because we are all too casual with the difference between immutable and mutable objects in Python. The arrays are mutable, so assigning a new value does not work as expected.
# classic example of mutabilty in action
a = ['spam', 'eggs', 100, 1234]
b = a
b.append("abc")
print a
# ['spam','eggs',100,1234,'abc'] # << note that a is altered when we only appended to b
print b
# ['spam','eggs',100,1234,'abc']
... View more
07-19-2012
03:57 AM
|
0
|
0
|
3275
|
|
POST
|
Use a Regular Expression to match names with letters to make a selection, then just do a copy on selected records. Regular expressions are supported in Python and are a very powerful text manipulation tool. Maybe we could assume that no names start with a digit, so you could reverse the search to look for any integer But if you didn't, an expression re.match('[A-Za-z ]+',inField) would allow any combination of letters and spaces # pseudocode (not run) for interactive Python window
# NOT field calculator (keep that for modelbuilder....)
import arcpy
import re
arcpy.env.workspace = "your_gdb_path"
cur = arcpy.UpdateCursor("table1")
for row in cur:
m = re.match('[0-9]+',row.inField) # matches any value beginning with integer string of digits
if not m : # ie not nothing found
row.nameCopy = m.string
cur.updateRow(row) # must not forget this or doesn't write to file
del cur # close cursor
# nameCopy is target field, inField is source field
... View more
07-19-2012
03:31 AM
|
0
|
0
|
5843
|
|
POST
|
Even if the compatibility extension allows you to open the xlsx file in ArcMap it is not a very good option because all the text fields are 255 chars wide. If you want to do a nice job, export the spreadsheet to a CSV format, define the field names, types and lengths in a schema.ini file and then load the CSV file. http://msdn.microsoft.com text file driver The ArcGIS loader will use the schema.ini file. Another way is to create a table in ArcMap and export it as a txt file. This will populate a schema.ini file which you can edit to point to the CSV file.
... View more
07-05-2012
06:58 PM
|
0
|
0
|
1041
|
|
POST
|
Sorry, can't help with server. I might now try installing ArcServer 10.1 since it is easier to manage.
... View more
07-05-2012
03:33 AM
|
0
|
0
|
2281
|
|
POST
|
Try using a template when you define a featureclass with the fields correctly set manually in ArcCatalog. Not quite an AddField for an existing table, but maybe you can adapt your workflow somehow. Or maybe use the SQL command ALTER TABLE in Python to add the fields yourself. Presumably that is all that AddField does in the background.
... View more
07-04-2012
03:31 AM
|
0
|
0
|
3487
|
|
POST
|
Perhaps a faulty route featureclass. Try adding hatching to be sure that you have the correct units. Are you mixing projections? The records will appear in the event table even if they are not mapping correctly, so that is not the issue. Maybe the route system line is doubled up or has some obscure editing fault, a gap in the route, or an inconsistent range. There are display options in properties to highlight some of these faults. Try creating a new route system with the expected range of values from your dbf file. There is a tool that you can add to a toolbar to query route systems in Customise mode that is useful. I find Linear Referencing very difficult to use, impossible to edit and have to create a copy each time I make an edit of the source. It was promised to be upgraded in 9.0, 9.1, 9.2, 9.3, 10.0, 10.1 and still no changes to even get it back to Workstation functionality.
... View more
07-04-2012
03:23 AM
|
0
|
0
|
1018
|
|
POST
|
Ok, I have edited your script to work in Pythonwin in Desktop to debug the script. I see that you are using ArcServer attributes, which is not a useful place to debug a script. I suspected that you had not installed python on the server, but if you get it to start, then that cannot be the case. # testbug.py
import arcinfo
import arcpy
import sys
def main():
## global mosaicDb
## global pathtable
# only a geoprocessing service can do this:
# pathtable = '%SCRATCHWORKSPACE%/Scratch.gdb/Paths'
# Desktop equivalent 9.3+
installTemp = arcpy.GetSystemEnvironment("ARCTEMPDIR")
arcpy.env.scratchWorkspace = installTemp+"/scratch.gdb"
if not arcpy.Exists(arcpy.env.scratchWorkspace):
print "failed to set scratch workspace"
sys.exit()
pathtable = arcpy.env.scratchWorkspace +"/Paths"
print pathtable
mosaicDb = r'D:\data\aerial\catalog\nzmgcat.gdb' # '//sdm7/arcgis/Mosaics/imagery_datasets.gdb/'
## inputmosaic = arcpy.GetParameterAsText(0)
## objectid = arcpy.GetParameterAsText(1)
inputmosaic = 'nztm1'
objectid = '40'
arcpy.AddMessage('Input Mosaic Dataset: ' + mosaicDb + "/" + inputmosaic) # bug fix added separator
arcpy.AddMessage('Search SourceObjectID: ' + objectid)
print 'Input Mosaic Dataset: ' + mosaicDb + "/" + inputmosaic
print 'Search SourceObjectID: ' + objectid
deletePathDb(pathtable)
exportCatalog(inputmosaic,pathtable,mosaicDb)
fs = getMosaicRow(objectid, pathtable)
print fs
arcpy.SetParameter(3, fs) # Not 0, this would have to be at least the third parameter
def deletePathDb(pathtable):
try:
if arcpy.Exists(pathtable):
arcpy.Delete_management(pathtable)
arcpy.AddMessage('table deleted successfully')
print 'pathtable deleted successfully'
else :
print 'pathtable does not exist'
except:
#catch because will throw error if table not there
print "error in deletePathDb"
arcpy.AddMessage('Error attempting delete path table')
arcpy.AddMessage(arcpy.GetMessages())
def exportCatalog(name,pathtable,mosaicDb):
try:
fullname = mosaicDb + '/' + name
arcpy.ExportRasterCatalogPaths_management(fullname, "ALL", pathtable)
except Exception as e:
arcpy.AddMessage("Error export catalog")
arcpy.AddMessage(arcpy.GetMessages())
def getMosaicRow(objectId, table):
where = 'SourceOID = ' + objectId # this is my objectid field name
#this was line that explodes
cursor = arcpy.SearchCursor(table, where)
fs = None
for row in cursor:
# fs = row # this will be a geoprocessing row object of no value outside the cursor
sPath = row.path
nSourceOID = row.SourceOID
nOID = row.OID
del cursor
return (nOID,nSourceOID,sPath)# return a tuple which contains the field contents
if __name__ == '__main__':
main()
c:\workspace/scratch.gdb/Paths
Input Mosaic Dataset: D:\data\aerial\catalog\nzmgcat.gdb/nztm1
Search SourceObjectID: 40
pathtable deleted successfully
(40, 40, u'D:\\data\\aerial\\catalog\\test\\r12a.jpg')
I cannot reproduce your error in Desktop.
... View more
07-04-2012
02:55 AM
|
0
|
0
|
2281
|
|
POST
|
It is easiest to install ARC/INFO workstation and use SHAPEARC to convert to a coverage, BUILD or CLEAN to fix the topology errors and then UNGENERATE. It might be possible from ArcGIS if you know how to use workstation, but I have never tried since it is so much better in the original workstation version.
... View more
07-03-2012
01:31 PM
|
0
|
0
|
1119
|
|
POST
|
I am suspicious of your query to open the cursor. Is ObjectID a string? If not it needs to be cast to a string. What happens if the result is no records? Add some print statements to print out what is returned. I have never used the row variable in a cursor, always row.attribute, what does row return? Update and Insert cursors work differently and since you haven't added a new row it probably just does nothing. You also need to close the cursor but I suppose that you are relying on the local variables in the function. I would still explicitly 'del cursor' You may have more success by rearranging your whole script. I would avoid opening and reopening a cursor just to get one record. Maybe get all the values in one pass and put into a python dictionary? That would be much faster.
... View more
07-03-2012
01:24 PM
|
0
|
0
|
2281
|
| Title | Kudos | Posted |
|---|---|---|
| 3 | Tuesday | |
| 1 | 3 weeks ago | |
| 1 | 03-11-2023 03:54 PM | |
| 1 | 09-15-2024 10:32 PM | |
| 1 | 03-12-2026 01:10 AM |
| Online Status |
Offline
|
| Date Last Visited |
Tuesday
|