POST
|
This should be all you need if you are going that route. fld_OBJID.type = "Long" This worked great, thank you!
... View more
06-06-2013
11:00 AM
|
0
|
0
|
590
|
POST
|
Matt, I'm having trouble understanding your solution in that thread because it is much more elaborate than what I'm trying to do. I just need to set one field to LONG or TEXT.
... View more
06-06-2013
10:20 AM
|
0
|
0
|
590
|
POST
|
I used an example in the thread you provided, and it seems to be working. But now it is failing on OID 32768. ERROR 001156: Failed on input OID 32768, could not write value '32768' to output field O_OID Failed to execute (FeatureClassToFeatureClass). try:
fieldmappings = arcpy.FieldMappings()
fieldmappings.addTable(CONVERSION_CPTestPoint)
fldmap_OBJID = arcpy.FieldMap()
fldmap_OBJID.addInputField(CONVERSION_CPTestPoint, "OBJECTID")
fld_OBJID = fldmap_OBJID.outputField
fld_OBJID.name = "O_OID"
fldmap_OBJID.outputField = fld_OBJID
fieldmappings.addFieldMap(fldmap_OBJID) Obvoiusly this new "O_OID" field is a short integer, how can I specify it as a LONG in the fieldmappings?
... View more
06-06-2013
09:57 AM
|
0
|
0
|
590
|
POST
|
I have field mapping working for all fields but when I try to pull the ObjectID's in I get an error message: "FieldMappings: Error in getting field map from field mapping for GetFieldMap" Here is my code: CONVERSION_InputPrefix = "Database Connections\\Sun120 - 5151.sde\\" CONVERSION_CPTestPoint = CONVERSION_InputPrefix + "CONVERSION.GasDataset\\CONVERSION.CPTestPoint" try: fieldmappings = arcpy.FieldMappings() fieldmappings.addTable(CONVERSION_CPTestPoint) fieldmap_CPTESTPOINT = fieldmappings.getFieldMap(fieldmappings.findFieldMapIndex("OBJECTID")) fieldmap_CPTESTPOINT.addInputField(CONVERSION_CPTestPoint, "OBJECTID") fieldmap_CPTESTPOINT = fieldmappings.getFieldMap(fieldmappings.findFieldMapIndex("GAS_CORR_TEST_STA_NO")) fieldmap_CPTESTPOINT.addInputField(CONVERSION_CPTestPoint, "GAS_CORR_TEST_STA_NO") fieldmap_CPTESTPOINT = fieldmappings.getFieldMap(fieldmappings.findFieldMapIndex("STATE_MCD")) fieldmap_CPTESTPOINT.addInputField(CONVERSION_CPTestPoint, "STATE_MCD") fieldmap_CPTESTPOINT = fieldmappings.getFieldMap(fieldmappings.findFieldMapIndex("DISTRICT_NAME")) fieldmap_CPTESTPOINT.addInputField(CONVERSION_CPTestPoint, "DISTRICT_NAME") fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("ANCILLARYROLE")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("ENABLED")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("CREATIONUSER")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("DATECREATED")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("DATEMODIFIED")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("LASTUSER")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("LEGACYID")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("INSTALLATIONDATE")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("COMMENTS")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("LOCATIONDESCRIPTION")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("OPERATINGSTATUS")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("PROPERTYUNITCODE")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("SUBTYPECD")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("SYMBOLROTATION")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("GASTRACEWEIGHT")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("ISR_NO")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("ISR_SEQ_NO")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("ISR_EXTERNAL_NO1")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("SAP_EQUIPMENT_NO")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("SAP_FUNCTIONAL_LOCATION")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("TESTPOINTTYPE")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("WIRECOUNT")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("APPT_NO")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("STREET_NAME1")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("STREET_NAME2")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("ZIP_CODE")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("DELETE_INDICATOR")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("CATHODICPROTECTIONDEVICE")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("CIVIC_NO")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("CPSYSTEMOBJECTID")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("CONVERSIONID")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("STR_SEQ_ID")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("IMAGEID")) fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("IMAGELINK")) except Exception as e: print e logging.error(": Error setting up field mappings: %s" %(str(e))) msgTxtErr = msgTxtErr + "\n" + "* Error setting up field mappings: " + str(e) flMail(from_addr, to_addr, msgTxtErr) Again if I comment out the ObjectID portion the code runs fine and I get the fields I want in the output. What do I have to do to get the existing ObjectID
... View more
06-06-2013
09:21 AM
|
0
|
7
|
3022
|
POST
|
Here is the key for 10.1 with Python 2.7:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command]
@="\"C:\\Python27\\ArcGIS10.1\\pythonw.exe\" \"C:\\Python27\\ArcGIS10.1\\Lib\\idlelib\\idle.pyw\" -e \"%1\""
Put this in a .reg file and ran it - restarted OS, no luck. : - / Checked the paths too...is it supposed to be a specific type? (String Value, Binary Value, DWORD...?) Thanks for the help.
... View more
05-09-2013
11:07 AM
|
0
|
0
|
559
|
POST
|
I have had a lot of success feeding variables into data paths for all other geoprocessing tools (this needs to be in the design so the script can be passed around different systems without modifying the code). But for this one it just will not take it. Here is what I have:
Path = os.getcwd() + "\\"
FileGDBName = "PSEG_Land_New"
FileGDBPath = Path + FileGDBName + ".gdb"
OldFileGDBName = "PSEG_Land"
OldFileGDBPath = Path + OldFileGDBName + ".gdb"
Locator = OldFileGDBPath + "\Dashboard_Locator"
refLocator = OldFileGDBPath + "\DM_AdjustedStreet_LN_Geocoding"
primTbl = "Primary Table"
arcpy.CreateAddressLocator_geocoding("US Address - Dual Ranges", '"' + "'" + refLocator + "' " + "'" + primTbl + "'" + '"', "'Feature ID' OBJECTID VISIBLE NONE;'*From Left' L_F_F_ADD VISIBLE NONE;'*To Left' L_T_F_ADD VISIBLE NONE;'*From Right' R_F_F_ADD VISIBLE NONE;'*To Right' R_T_F_ADD VISIBLE NONE;'Prefix Direction' PREFIX VISIBLE NONE;'Prefix Type' NAMEPREFIX VISIBLE NONE;'*Street Name' NAME VISIBLE NONE;'Suffix Type' TYPE VISIBLE NONE;'Suffix Direction' SUFFIX VISIBLE NONE;'Left City or Place' L_APNAME VISIBLE NONE;'Right City or Place' R_APNAME VISIBLE NONE;'Left ZIP Code' POSTAL_L VISIBLE NONE;'Right ZIP Code' POSTAL_R VISIBLE NONE;'Left State' <None> VISIBLE NONE;'Right State' <None> VISIBLE NONE;'Left Street ID' <None> VISIBLE NONE;'Right Street ID' <None> VISIBLE NONE;'Min X value for extent' <None> VISIBLE NONE;'Max X value for extent' <None> VISIBLE NONE;'Min Y value for extent' <None> VISIBLE NONE;'Max Y value for extent' <None> VISIBLE NONE;'Left Additional Field' <None> VISIBLE NONE;'Right Additional Field' <None> VISIBLE NONE;'Altname JoinID' <None> VISIBLE NONE", Locator, "")
This gives me: ExecuteError: Failed to execute. Parameters are not valid. ERROR 000039: Not enough reference data tables for this style. Failed to execute (CreateAddressLocator). The problem is from the part where you provide the input data for the locator to be built off of. I have the syntax down perfect, if I add print '"' + "'" + refLocator + "' " + "'" + primTbl + "'" + '"' I get "'C:\Working Folders\GIS\Dashboard_Updates\PSEG_Land.gdb\DM_AdjustedStreet_LN_Geocoding' 'Primary Table'". If I input this path into the piece where it takes the input, the tool will run. Completely baffled by this.
... View more
05-09-2013
10:54 AM
|
0
|
2
|
2397
|
POST
|
So I installed the 64-bit background geoprocessing service along with SP1 and all of my scripts broke (and python thought I was running an AMD64 when I am running Intel). So after uninstalling my machine no longer associated .py files with IDLE. I used the Windows "Default Programs" control to make the association, but I still don't have the option in the drop-down. IDLE opens when I double click a.py file (the icon has no image). I've spent hours trying to get this to work and searching everywhere. Would appreciate any help. Also, what changes need to be made to work with 64-bit background geoprocessing? Thanks.
... View more
05-09-2013
05:29 AM
|
0
|
4
|
1524
|
POST
|
Solved this by creating an entirely new mxd. The original was not "corrupt" but there was something causing an issue. Thanks for the help.
... View more
05-08-2013
11:55 AM
|
0
|
0
|
687
|
POST
|
I'm currently testing the process on separate machines - one running 10.0 and my main workstation running 10.1. I'll let you know what I find.
... View more
05-01-2013
09:31 AM
|
0
|
0
|
687
|
POST
|
I found out that I cannot even pan to the features in the map document. The rest of the script - the part before the loop that exports the jpeg images - performs spatial selections and queries against point features to detect clusters of gas leaks and writes them to a gdb. The layers in the saved map document point to these new features. When I try to pan to the 24th record it crashes ArcMap.
... View more
05-01-2013
07:32 AM
|
0
|
0
|
687
|
POST
|
So pythonw.exe is still crashing, I don't think it has anything to do with what I previously thought. I I comment that out, it will get through 14 or so images and then crash. Can anyone see anything wrong with my code / how to optimize it? Thanks.
... View more
05-01-2013
05:37 AM
|
0
|
0
|
687
|
POST
|
I had some code working previously that is now causing pythonw.exe to crash. I have an .mxd set up that I am using to loop through features in a layer and export the layout to jpeg. However now the script crashes when it gets to df.zoomtoselectedfeatures. Here is what I have: import arcpy Path = os.getcwd() GSP_Join = "C:\\Users\\TDMC0\\AppData\\Local\\Temp\\scratch.gdb\\GSP_Join" mxd = arcpy.mapping.MapDocument(Path + r"\GasLeaks2013.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] Layer = arcpy.mapping.ListLayers(mxd, "", df)[0] Layer2 = arcpy.mapping.ListLayers(mxd, "", df)[1] Layer3 = arcpy.mapping.ListLayers(mxd, "", df)[2] # Create a search cursor try: rows = arcpy.SearchCursor(GSP_Join, "", "", "CONN_OBJ_ID_NUM", "CONN_OBJ_ID_NUM") except Exception as e: print e # Iterate through the Implausible Reads Feature, getting and zooming to respective extents and exporting layout to JPEG. currentState = " " count = arcpy.GetCount_management(GSP_Join) progress = 1 for row in rows: try: if currentState != row.CONN_OBJ_ID_NUM: print "\rExporting Data Driven Pages to JPEG...%s of %s" %(progress, count) currentState = row.CONN_OBJ_ID_NUM where_clause = "\"CONN_OBJ_ID_NUM\"=" + "'" + currentState + "'" arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", where_clause) df.zoomToSelectedFeatures() df.scale = 5500 arcpy.RefreshActiveView() arcpy.SelectLayerByAttribute_management (Layer, "CLEAR_SELECTION", "") Layer.definitionQuery = where_clause Layer2.definitionQuery = where_clause Layer3.definitionQuery = where_clause arcpy.mapping.ExportToJPEG(mxd, r"E:\GasLeaksProject\2012\JPEG\CONN_OBJ_ID_NUM" + str(currentState) + ".jpeg", resolution=300, jpeg_quality=70) Layer.definitionQuery = "" Layer2.definitionQuery = "" Layer3.definitionQuery = "" progress = progress + 1 except Exception as e: print e When I run this I get a Windows OS message saying "pythonw.exe has crashed". I narrowed it down to the line df.zoomToSelectedFeatures() (if I comment out this line the code runs but obviously does not output what I want). Again this was working previously (about six months ago) I must have tested it a hundred times. All of the data sources are working in the mxd, and I tried re-saving the mxd and pointing to the new copy but no luck. I also printed my where_clause and it looks good. It must be a problem with my "list data frames / list layers code". Any help would be appreciated.
... View more
04-30-2013
06:28 AM
|
0
|
7
|
1182
|
POST
|
Thanks I added the "\\" but am still getting errors due to schema locks. I was under the impression that could not happen (hence the whole point of the scratchGDB environment). If there is something else I am doing wrong please let me know. I will implement the in-memory workspace after testing is complete but in the development stage I need to see the intermediate tables structures.
... View more
04-29-2013
08:52 AM
|
0
|
0
|
456
|
POST
|
In scripting business processes it is coming up again and again where I need an intermediate workspace to write data. I am trying to copy a table to the scratch workspace but it is placing the table into a dbf in the folder where the scratchGDB is located. Here is what I have:
import arcpy, arceditor, logging, datetime, os, smtplib
from arcpy import env
arcpy.env.overwriteOutput = True
InputPrefix = "Database Connections\\Sun130 - 5151.sde\\"
tblImplsblRd = InputPrefix + "GIS_INTERFACE.SAP_IMPLAUSIBLE_READS"
lclImplsblRd = env.scratchGDB + "SAP_IMPLAUSIBLE_READS"
def copyRows(src, trgt, cfg):
try:
arcpy.CopyRows_management(src, trgt, cfg)
logging.info(": Copied %s to %s" %(src, trgt))
except Exception as e:
print e
logging.error(": %s" %(e))
msgTxtErr = msgTxtErr + "\n" + "* " + str(e)
errValue = 1
copyRows(tblImplsblRd, lclImplsblRd, "")
print "done"
When I run this from a script exported from ModelBuilder it places the table into the temporary gdb:
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# temp.py
# Created on: 2013-04-29 10:29:12.00000
# (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
# Local variables:
GIS_INTERFACE_SAP_IMPLAUSIBLE_READS = "Database Connections\\Sun130 - 5151.sde\\GIS_INTERFACE.SAP_IMPLAUSIBLE_READS"
SAP_IMPLAUSIBLE_READS = "C:\\Users\\TDMC0\\AppData\\Local\\Temp\\scratch.gdb\\SAP_IMPLAUSIBLE_READS"
# Process: Copy Rows
arcpy.CopyRows_management(GIS_INTERFACE_SAP_IMPLAUSIBLE_READS, SAP_IMPLAUSIBLE_READS, "")
However if the path to the scratch GDB is hard-coded I will lose the ability to have a gauranteed space to write data. Would appreciate help getting this working correctly.
... View more
04-29-2013
06:37 AM
|
0
|
4
|
772
|
Title | Kudos | Posted |
---|---|---|
1 | 02-18-2014 07:08 AM | |
1 | 02-27-2014 05:22 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|