beginner command/scripting/python help, 9.3

1009
9
03-21-2013 11:17 AM
ChrisJ
by
New Contributor III
hi guys, long time lurker first time poster...

if the information I'm after is already elsewhere, please point me in the right direction if it's faster.

I've just started using arcgis 9.3 (no arcinfo) after years of using mapinfo.  what I'd like to do is just type my commands in arc much like the command line in mapinfo; sql commands for one would be amazing.  this doesn't seem apparent in arcgis 9.3 but I could be wrong.  I see the command line window but I'm not familiar with the syntax or functions found therein yet.  what I used to do in mapinfo was write code in mapbasic, then run those mapbasic programs in mapinfo; can something similar be done here?  if python is what I need to learn I don't mind, it's the linking of a working python script (and validation/compilation of that script) to arcmap9.3 that concerns me.

my first task is to compare two point layers for example; find the 5 closest points in layer1 for each point in layer2 in ascending order (ie. ignoring the 6th closest point or farther); any good starting points or things to consider first?

thanks very much in advance for any input...

cj
Tags (2)
0 Kudos
9 Replies
MichaelVolz
Esteemed Contributor
Is it possible for you to upgrade to 10.0 or 10.1?  Python has more functionality than in 9.3.
0 Kudos
curtvprice
MVP Esteemed Contributor
If python is what I need to learn I don't mind, it's the linking of a working python script (and validation/compilation of that script) to arcmap9.3 that concerns me.


The command window in ArcGIS 9.3 is replaced with a real-live Python prompt ">>>" window in ArcGIS 10.0

In 10.0, the geoprocessor (gp) is still there and even deprecated tools and are still available if you crank up a geoprocessing object the 9.3 way (arcgisscripting.Create(9.3)). If you have a working Python script in 9.3, it will run without modification in 10.0. Updating 9.3 scripts to use 10.0 arcpy is not too difficult - except for spatial analyst, which involves learning "the new way to do it" with Python map algebra.

my first task is to compare two point layers for example; find the 5 closest points in layer1 for each point in layer2 in ascending order (ie. ignoring the 6th closest point or farther); any good starting points or things to consider first?


The easy way to do this (the Point Distance tool) requires ArcGIS Advanced (formerly ArcInfo). Join By Location if you are limited to ArcGIS Basic (formerly ArcView).
Python scripts are linked to ArcGIS Desktop by way of creating a toolbox and adding scripts and models. Toolboxes, script tools, and ModelBuilder models (mostly) run unmodified in 10.0.
0 Kudos
ChrisJ
by
New Contributor III
thankyou both for your quick responses...

for the time being I expect to have arcgis 9.3 only, though with arcinfo capability.  as I said I'm coming from a mapinfo background so please excuse if I name something incorrectly or misunderstand an analogue between them.

perhaps my task can give you some insight into where I should post this, quickly...

point layer1 has say 10 points
point layer2 has say 100 points spread over the same area as layer1
what I want is to know the five closest points from layer2 for each point in layer1...

for each layer1.obj, i <=5, i++
    find next closest layer2.obj
end loop

results would be something like:

layer1 item1 (1,2,3,4,5 closest points from layer2 and their distances)
layer1 item2 (1,2,3,4,5 closest points from layer2 and their distances)
...
layer1 item10 (1,2,3,4,5 closest points from layer2 and their distances)

with admittedly whimsical syntax that is what i'm picturing; if someone could translate that into an arc environment I'd be very grateful, or point me to the proper forum....

thanks again,

cj
0 Kudos
curtvprice
MVP Esteemed Contributor
for the time being I expect to have arcgis 9.3 only, though with arcinfo capability. 


In that case, try the Point Distance tool. The output will give you something you can easily manipulate to get what you want.
0 Kudos
ChrisJ
by
New Contributor III
thanks for this; I've found the PD tool and can see the output....if you or someone has time; what's the best approach for a beginner to take to get this sort of thing automated, ie. a script, and one with more detail (ie. a for loop and that type of control), is this possible in arcgis9.3?  again if it helps someone make a link for me; I'm quite used to mapinfo and its mapbasic files, and command line control (including SQL)...

thanks again curtvprice and all...

cj
0 Kudos
MichaelVolz
Esteemed Contributor
Here's the Help for 10.0 for the Point Distance Tool

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00080000001r000000

Sample from this page

# Description: Finds distance of each near point from each input point and outputs to a table.
 
# import system modules
import arcpy - You would need to reference gp object in 9.3 instead of newer arcpy object (same thing goes for all other references to arcpy in this sample script)
 
# set workspace environment
arcpy.env.workspace = "C:/data/pointdistance.gdb"
 
# set variables
in_features = "police_stations"
near_features = "crime_location"
out_table = "crime_distance4"
search_radius = "22000 Feet"
 
try:
    # find crime locations within the search radius
    arcpy.PointDistance_analysis(in_features, near_features, out_table, search_radius)
    print arcpy.GetMessages(0)
   
except arcpy.ExecuteError:
    print arcpy.GetMessages(2)
   
except Exception as ex:
    print ex.args[0]
0 Kudos
ChrisJ
by
New Contributor III
appreciate it, thanks for the link mvolz47...

edit: thanks again, though I'm stuck with 9.3 for the time being, so this link may not be for me just yet...
0 Kudos
MichaelVolz
Esteemed Contributor
For v9.3

import arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

# Process: Copy Feature Class of cache features(2)...
gp.FeatureClassToFeatureClass_conversion(TRANSPORTATION_RDCL_SDE, Transportation_gdb, "RDCL_SDE_COPY", "")

This shows you have to initiate the gp object and then use it in your geoprocessing methods such as FeatureClassToFeatureClass_conversion.

You should be able to find more 9.3 based python scripting info from the forum threads and you could always google for more links.
0 Kudos
ChrisJ
by
New Contributor III
I'll give this a try, thanks for your help mvolz47...

edit: was very helpful, after a bit of tinkering comes back with no errors and some results.  this was run:

import arcgisscripting

# create the geoprocessor object
gp = arcgisscripting.create(9.3)

gp.workspace = "I:\PDtest"

# process
gp.PointDistance_analysis("stores.shp", "competitors.shp", "output.dbf", "1000 meters")

however, all point distances were returned, not only those within 1000m?  it's fine for now but I'll need to figure out why that might be; I admit I'm unsure about how projections work here in arc (as opposed to mapinfo).  distances in output were reported in decimal degrees by the look of it; next steps?

I would also like to be able to run pointdistance and only find those first 5 closest to each point, which I guess with some tinkering in the python script can be done?

thanks again,

cj
0 Kudos