Modelbuilder, SpatialEcology Tools

411
4
12-07-2010 10:34 AM
JohannesRadinger
New Contributor
Hello...

...I am new in using Python and I think you can help me very quick...

I want to use the snappoints-feature from SpatialEcology (former Hawths tools, SpatialEcology.com) as a tool in the modelbuilder. Therefore I have to use the snappoints-code in a phython-environment and save that script so that I can use it in the modelbuilder. I don't know how to write the script.

The manual says:
[INDENT]You must first load the �??os�?? Python library (using: �??import os�??) at the beginning of your Python session. To call GME from the command line you use the following generic syntax: os.system(�?�path\\SEGME.exe commands�?�)[/INDENT]


the total manual can be found here.

I know my command which is:
snappoints(in, snap, out, tol, [where]);

in --> the input point data source
snap--> the input feature source to which points are snapped
out--> the output point data source
tol--> the maximum snap distance in coordinate system units
[where] the selection statement that will be applied to the point feature data source to identify a subset of points to process (see full Help documentation for further details)

Example 1: snappoints(in="C:\data\locs.shp", snap="C:\data\roads.shp", out="C:\data\snappedlocs.shp", tol=5000);


But I'd like to use the input/output-variables from the modelbuilder rather than to set the input as fixed paths (like in the example). Maybe one of you can just help me and support me with the script.

thanks
johannes
Tags (2)
0 Kudos
4 Replies
JohannesRadinger
New Contributor
So,
I've tried my first small script to use it as a tool in the model builder.
At the moment I don't have the possibilty to run it, but do you think that
can work? What is missing in the code?

#Import library modules
import os arcpy

# Read parameter values
# 1 in --> the input point data source 
# 2 snap--> the input feature source to which points are snapped 
# 3 out--> the output point data source 
# 4 tol--> the maximum snap distance in coordinate system units 

 in = arcpy.GetParameterAsText(0)
 snap = arcpy.GetParameterAsText(1)
 out = arcpy.GetParameterAsText(2)
 tol = arcpy.GetParameterValue(3)
 
#Loading GME and running GME-Tool
os.system(�?�path\\SEGME.exe -c snappoints(in, snap, out, tol)�?�)


how does it it work with the parameters to be used in the SEGME?

/j
0 Kudos
JohannesRadinger
New Contributor
So,
with some help of a friend I tried to develop the script,
What do you think about?

# ---------------------------------------------------------------------------
# gis_Test1.py

# Description: Snap Point to Feature (Spatial Ecology)
# ---------------------------------------------------------------------------

import os 
import arcpy

#Read Parameters
#1 in --> the input point data source
#2 snap --> the input feature source to which points are snapped
#3 out --> the output point data source
#4 tol --> tbe maximum snap distance in coordinate system units

inpoint = arcpy.GetParametersAsText(0)
snap = arcpy.GetParametersAsText(1)
outpoint = arcpy.GetParametersAsText(2)
tol = arcpy.GetParametersAsValue(3)
  

os.system("C:\\Program Files (x86)\\SpatialEcology\\GME\\SEGME.exe -c snappoints(in=\\\"%s\\\", snap=\\\"%s\\\", out=\\\"%s\\\", tol=%s);" %(inpoint, snap, outpoint, tol)) 


The problem is that I get the error:
'module' object has no attribute

what is the problem?
thank you...
j
0 Kudos
JohannesRadinger
New Contributor
So I already solved some problems...spelling mistakes 😉
but I don't get any output...

I read in the GME-handbook that geodatabases and their path is handled different
in GME. A path should look like e.g C:\data\europe!transport!roads, where europe =
geodatabase, transport = feature dataset and roads = featureclass and the are separated
by !



# ---------------------------------------------------------------------------
# gis_Test1.py

# Description: Snap Point to Feature (Spatial Ecology)
# ---------------------------------------------------------------------------

import os 
import arcpy

#Read Parameters
#1 inpoint --> the input point data source
#2 snap --> the input feature source to which points are snapped
#3 outpoint --> the output point data source
#4 tol --> tbe maximum snap distance in coordinate system units


inpoint = arcpy.GetParameterAsText(0)
snap = arcpy.GetParameterAsText(1)
outpoint = arcpy.GetParameterAsText(2)

os.system("C:\\Program Files (x86)\\SpatialEcology\\GME\\SEGME.exe -c snappoints(in=\\\"%s\\\", snap=\\\"%s\\\", out=\\\"%s\\\", tol=500);" %(inpoint, snap, outpoint)) 


can anyone pls help, the problem is the same for all gme tools and a solution would help
everybody working with the spatial ecology tools (GME, former Hawths tools)

thank you very much
0 Kudos
SteveHanser
New Contributor
Were you ever able to resolve this issue? Please post your final code if you were.
0 Kudos