POST
|
Hi Dan, The original script i was working with was an Export from a ModelBuilder Model I was working on. ModelBuilder seems to have exported it with extra arguments
... View more
05-26-2015
10:25 AM
|
0
|
0
|
412
|
POST
|
Thanks Sephe Fox, The paths were ok to have spaces (this was the test data, real data resides on a lengthy server path) Changing the syntax of the tools cause python to produce an actual error rather than crashing: Rescale By Function() takes at most 4 arguments (currently 7 total) the solution is to create a transformation function object to pass into the tool, works great now: # Create the TfLarge object - to pass into the Rescale By Function Tool midpoint = median_Result spread = 5 lowerthresh = "#" valbelowthresh = "#" upperthresh = "#" valabovethresh = "#" myTfFunction = TfLarge(midpoint, spread, lowerthresh, valbelowthresh, upperthresh, valabovethresh) # Process: Rescale by Function - rescale integer raster from 0 to 1 passing in MEDIAN value Final_Test = RescaleByFunction(as_ppb_int, myTfFunction, "0", "1") http://resources.arcgis.com/en/help/main/10.2/index.html#//005m000000s9000000
... View more
05-26-2015
10:18 AM
|
1
|
0
|
412
|
POST
|
Hello, I am attempting to use the Rescale By Function tool rescale my raster values using the "LARGE" transformation function, however instead of using the calculated value for the midpoint parameter, I would like to use the MEDIAN. In this code I convert the float raster to integer, get the median using zonal stats, convert the Result Object to long integer, and pass it into the Rescale By Function parameters. # Import arcpy module
import arcpy
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
# Local variables:
as_ppm = "C:\\Users\\nmoylan\\Documents\\Desktop Items\\Strategic Evaluations\\BC\\QUEST WEST\\Z9 Geochem and Grids\\as_ppm"
Constant_value = "1000"
process_mask = "C:\\Users\\nmoylan\\Documents\\Desktop Items\\Strategic Evaluations\\BC\\QUEST WEST\\Z9 Geochem and Grids\\process_mask"
as_ppb_int = "C:\\Database\\ARCGIS\\Geoprecessing\\Scratch\\as_ppb_int"
as_median = "C:\\Database\\ARCGIS\\Geoprecessing\\Scratch\\as_median"
as_ppb = "C:\\Database\\ARCGIS\\Geoprecessing\\Scratch\\as_ppb"
Final_Test = "C:\\Database\\ARCGIS\\Geoprecessing\\Scratch\\Final_Test"
# Process: Times
arcpy.gp.Times_sa(as_ppm, Constant_value, as_ppb)
# Process: Int - makes the MEDIAN option available in Zonal Stats
arcpy.gp.Int_sa(as_ppb, as_ppb_int)
# Process: Build Raster Attribute Table - Greater than 100000 values and 500 unique values
arcpy.BuildRasterAttributeTable_management(as_ppb_int, "Overwrite")
# Process: Zonal Statistics - to find the MEDIAN
arcpy.gp.ZonalStatistics_sa(process_mask, "VALUE", as_ppb_int, as_median, "MEDIAN", "DATA")
# Convert the Result Object from Zonal Stats to Long Integer Value
median_Result = long(arcpy.GetRasterProperties_management(as_median, "MEAN").getOutput(0))
print median_Result
# Process: Rescale by Function - rescale integer raster from 0 to 1 passing in MEDIAN value
arcpy.gp.RescaleByFunction_sa(as_ppb_int, Final_Test, "LARGE", median_Result, "5", "# # # #", "0", "1")
print "Complete" When I run it I get the following (6833 being the MEDIAN): the dialog eventually dissapears without producing the 'Final_Test' raster. I really just need a way of using the median as opposed to the mean to perform the LARGE transformation function. Thanks, Nick
... View more
05-26-2015
09:07 AM
|
0
|
4
|
2673
|
POST
|
Hello, I have a model that calculates an integer field with the DateDiff() function. The difference is between an 'expiry_date'(date type) field formatted "mm/dd/yyyy" and the now() function. I want to export this model to a Python script, however it wont allow the VB function to be used. It is a large model that I would rather not rewrite, is there python code that I can use in the tool before I export it to a python script in place of the VB to calculate this integer field??
... View more
10-03-2014
11:25 AM
|
0
|
2
|
14094
|
POST
|
Hello, I'm using ArcGIS Desktop 10.1 SP1. I was working on a feature class within a file goedatabase and made a few minor edits (create a new feature, cut a feature in two) I ended the edit session without incident and proceeded to recalculate some fields by selecting records, again no issues. I then tried to delete an unwanted field, this gave me an error "General function Failure" and then wiped out my feature table. The feature class will no longer add to any of my projects and is unviewable in ArcCatalog, I can however see the properties for it and can see that all the fields are still there. It almost seems as though there is no link between the geometry and the attributes. Is there a way that I can either repair the file or export the tabular data from the feature class at least? any help is appreciated. Thanks, Nick
... View more
03-03-2014
09:08 AM
|
0
|
2
|
1313
|
POST
|
Hi, I am have been creating TIN using the Las Dataset to TIN tool. I am setting the Extents in the environment settings of the tool to be the same as a bounding box polygon. the problem arises only at the edges of the extents polygon; vertical faces are created at the edges of the TIN surface. Is there a way to prevent these vertical faces during the generation of the TIN, or remove them afterwards? Any help is appreciated, -Nick [ATTACH=CONFIG]26175[/ATTACH]
... View more
07-24-2013
06:55 AM
|
0
|
1
|
565
|
POST
|
Thanks for the help, I am posting my completed code below if anyone is interested. The comments might not all be 100% correct, but they're close. The client wanted everything commented, so it's a little comment heavy. Criticism is welcome. Enjoy!!
Option Explicit 'Requires user to declare all of your variables
'Below, the user will have to declare two constant values
'Const path As String = "E:/School/Semester3/GIS4309/my_id_tags_92.txt" 'path of the text file being written to
'Const layerName As String = "TestPoints" 'Name of the Layer to be tracked
Private m_pEditor As IEditor 'Declare an IEditor variable to be available at the module level
Private WithEvents EditEvents As Editor 'use the WithEvents keyword and provide appropriate functions to handle the events.
'Declare variables available to the whole module
Dim pMap As IMap
Dim prevData As String
Dim IdTag As String
Dim pMxDoc As IMxDocument
Dim pFeatureLayer As IFeatureLayer
Dim pFeature As IFeature
Dim pLayer As ILayer
Dim pEnumLayer As IEnumLayer
Dim fileNum As Integer
Dim fileNum2 As Integer
Dim pEditLayers As IEditLayers
Dim pID As New UID
Dim targetLayer As IFeatureLayer
Public path As String
Public layerName As String
'will run the StartListeningToEditEvents subroutine when the button is clicked
'It will also prompt the user to enter the path to the text file for storing the info and the Layer to listen to
Public Sub TagListener_Click()
'path = "E:/School/Semester3/GIS4309/my_id_tags_92.txt" 'path of the text file being written to
layerName = "TestPoints" 'Name of the Layer to be tracked
vaFiles = Application.GetOpenFilename(FileFilter:="Excel Filer (*.txt),*.txt", Title:="Open File", MultiSelect:=False)
'This section will prompt the user to enter the path to the text file for storing the info
Dim newpath As String
newpath = InputBox("Please enter the path to your Tag Tracking File (ie: E:/School/Semester3/GIS4309/my_id_tags_92.txt)", "Path Required", path)
If StrPtr(newpath) = 0 Or newpath = "" Then 'Handles the Cancel button or if the user enters nothing
Exit Sub
End If
'This section will prompt the user to enter the name of the Layer in the map document to listen to
Dim newlayername As String
newlayername = InputBox("Please enter the layer name you are tracking (ie: MyPoints)", "Layer Name Required", "TestPoints")
If StrPtr(newlayername) = 0 Or newlayername = "" Then 'Handles the Cancel button or if the user enters nothing
Exit Sub
End If
'These two staements will pass the user input into these variables for use later on in the code
path = newpath
layerName = newlayername
StartTagListener 'call to this subroutine
End Sub
'This sub will be the macro that the button on the toolbar runs
Public Sub StartTagListener()
Set EditEvents = Application.FindExtensionByName("ESRI Object Editor") 'Listen for events in the editor environment
End Sub
'This sub will listen for any features that are being deleted
'it will then write the OBJECTID Tag of the object to the external text file
'only if the feature being deleted is a a point feature
'when listening for the delete event, the sub will note the object being deleted
Private Sub EditEvents_OnDeleteFeature(ByVal obj As IObject)
Set pMxDoc = ThisDocument 'Sets the pMxDoc to the current document using the ThisDocument keyword
'This next section set up access to the ESRI Editor Library
'this library implements ArcMap's object editor including the
'editing of feature geometry and attributes as well as
'topological display and editing
pID = "esriEditor.Editor" 'Sets the pID variable to the UID with this name
Set m_pEditor = Application.FindExtensionByCLSID(pID) 'creates the access to the ESRIEditor Library
'Declare Variables for use in this section of the code
Dim pFeature As IFeature
Dim pGeometry As IGeometry
'This next line will set the current object being deleted to the feature variable
'This line is important as it will allow the GeometryType property to act on the IObject
Set pFeature = obj
If pFeature.Shape.GeometryType = esriGeometryPoint Then 'Will run the code if the Feature's geometry type is a point type
IdTag = obj.OID 'Sets the IdTag variable to the OID of the object being deleted
fileNum = FreeFile 'Obtain next free file handle number.
Open path For Input As #fileNum 'Opens the file for reading
'This loop will store all the text from the beginning to the End of the File (EOF)
Do While Not EOF(fileNum)
Input #fileNum, prevData 'stores string data in the prevData variable
Loop
Close #fileNum 'must always close the file
fileNum2 = FreeFile 'Obtain next free file handle number.
Open path For Output As #fileNum2 'Opens file for writing
'the next line appends a string of content to the top of the text file
'including the deleted tag ID in brackets, The current date and time,
'and a TAG DELETED Marker
Write #fileNum2, vbCrLf & "(" & IdTag & ")" & vbTab & vbTab & Format(Now, "dd-mmm-yyyy hh:mm:ss AM/PM") & vbTab & "*TAG DELETED*" & vbCrLf & prevData
Close #fileNum2 'must always close the file
'MsgBox "Point Deleted: " & obj.OID 'Displays a message box when a feature is deleted --> for testing only
Exit Sub
Else
'MsgBox "Line Deleted: " & obj.OID 'Displays a message box when a feature is deleted --> for testing only
Exit Sub 'will exit the sub if the layer names do not match and write nothing to the file
End If
End Sub
'This sub will listen for any features that are being created
'it will then write the OBJECTID Tag of the object to the external text file
'only if the target layer selected is that of the layer we wish to
'record the ID's of ie: TestPoints Layer
'when listening for the create event, the sub will note the object being deleted
Private Sub EditEvents_OnCreateFeature(ByVal obj As IObject)
Set pMxDoc = ThisDocument 'Sets the pMxDoc to the current document using the ThisDocument keyword
'This next section set up access to the ESRI Editor Library
'this library implements ArcMap's object editor including the
'editing of feature geometry and attributes as well as
'topological display and editing
pID = "esriEditor.Editor" 'Sets the pID variable to the UID with this name
Set m_pEditor = Application.FindExtensionByCLSID(pID) 'creates the access to the ESRIEditor Library
Set pEditLayers = m_pEditor 'QI
'sets the tagetLayer variable to the layer currently selected in the editor's taget drop-down list
Set targetLayer = pEditLayers.CurrentLayer
' Get all the layers in the Map
Set pEnumLayer = pMxDoc.FocusMap.Layers
Set pLayer = pEnumLayer.Next 'Sets pLayer to the first layer in the table of contents window
' Loop through all the layers until the desired layer name is found
Do Until pLayer Is Nothing
If pLayer.Name = layerName Then
Exit Do
End If
Set pLayer = pEnumLayer.Next 'If the layer name was not found, go to next layer
Loop
Set pFeatureLayer = pLayer 'QI
If pFeatureLayer.Name = targetLayer.Name Then 'Will run the code if the FeatureLayer and targetLayer have the same name
IdTag = obj.OID 'Sets the IdTag variable to the OID of the object being deleted
fileNum = FreeFile 'Obtain next free file handle number.
Open path For Input As #fileNum 'Opens the file for reading
'This loop will store all the text from the beginning to the End of the File (EOF)
Do While Not EOF(fileNum)
Input #fileNum, prevData 'stores string data in the prevData variable
Loop
Close #fileNum 'must always close the file
fileNum2 = FreeFile 'Obtain next free file handle number.
Open path For Output As #fileNum2 'Opens file for writing
'the next line appends a string of content to the top of the text file
'including the deleted tag ID in brackets, and the current date and time
Write #fileNum2, vbCrLf & IdTag & vbTab & vbTab & Format(Now, "dd-mmm-yyyy hh:mm:ss AM/PM") & vbCrLf & prevData
Close #fileNum2 'must always close the file
Else
Exit Sub 'will exit the sub if the layer names do not match and write nothing to the file
End If
'MsgBox "EditEvents_OnCreateFeature : " & obj.OID 'Displays a message box when a feature is deleted --> for testing only
End Sub
'This function will add a Tool Tip to the UI button
'When the user hovers over the button it will provide info on what it does
Private Function TagListener_ToolTip() As String
TagListener_ToolTip = "Click this button to start listening for tage creation/deletion events" 'Tool Tip statement
End Function
... View more
07-25-2010
03:38 PM
|
0
|
0
|
163
|
POST
|
Hello all, I'm using the OnDeleteFeature Event to monitor for deleted POINTS only and then write the ID to a text file. I've set up a test map document where I have point and line layers. If I delete a single point or group of points, they are recorded --> This is good If I delete a single line or group of lines, they are not recorded --> This is also good However, if I have a selection of lines and points and delete them, it will record them all as deleted points. I need the code to only record the points of the selection and not the lines. I have the OnDeleteFeature sub that I am using below. If anyone has Ideas I would really appreciate it. Thanks, Nick Private Sub EditEvents_OnDeleteFeature(ByVal obj As IObject) Set pMxDoc = ThisDocument pID = "esriEditor.Editor" Set m_pEditor = Application.FindExtensionByCLSID(pID) Dim pFeature As IFeature Dim pGeometry As IGeometry Dim pEnumFeat As IEnumFeature Set pEnumFeat = m_pEditor.EditSelection Set pFeature = pEnumFeat.Next Do While Not pFeature Is Nothing If pFeature.Shape.GeometryType = esriGeometryPoint Then IdTag = obj.OID fileNum = FreeFile Open path For Input As #fileNum 'Opens the file for reading Do While Not EOF(fileNum) Input #fileNum, prevData 'stores string data in the prevData variable Loop Close #fileNum 'must always close the file fileNum2 = FreeFile Open path For Output As #fileNum2 'Opens file for writing Write #fileNum2, vbCrLf & "(" & IdTag & ")" & vbTab & vbTab & Format(Now, "dd-mmm-yyyy hh:mm:ss AM/PM")_ & vbTab & "*TAG DELETED*" & vbCrLf & prevData Close #fileNum2 'must always close the file MsgBox "Point Deleted: " & obj.OID Exit Sub Else MsgBox "Line Deleted: " & obj.OID Exit Sub End If Set pFeature = pEnumFeat.Next Loop End Sub
... View more
07-13-2010
12:22 PM
|
0
|
2
|
607
|
Title | Kudos | Posted |
---|---|---|
1 | 05-26-2015 10:18 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|