[Tutor] Increment by string, Array
Joel Goldstick
joel.goldstick at gmail.com
Thu Dec 9 21:22:48 CET 2010
Can you use something like this:
for i in range(1,201):
s = str(i)
Then Path = '1' can become Path = s
On Thu, Dec 9, 2010 at 2:39 PM, <lmhosie at jacks.sdstate.edu> wrote:
> Hello,
> I have a large code that I am using for ARC GIS I know could be much
> smaller but it works like it is. I have programmed in C++ but am just
> beginning with python I believe the answer would be to do a parallel array
> however I am having trouble keeping the SQL statment in the string format it
> should be and putting in the array. So I ended up using a string.template
> and just incrementing manually.
> Here is a sample of the code:
>
> #
> ---------------------------------------------------------------------------
> # MakeFeature.py
> # Created on: Tue Nov 23 2010 11:07:25 AM
> #
> #
> ---------------------------------------------------------------------------
> # Import system modules
> import sys, string, os, arcgisscripting
> # Create the Geoprocessor object
> gp = arcgisscripting.create()
> gp.overwriteoutput = 1
> # Check out any necessary licenses
> gp.CheckOutExtension("spatial")
> # Load required toolboxes...
> gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Spatial
> Analyst Tools.tbx")
> gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data
> Management Tools.tbx")
>
> # Local variables...
> wrs_season_Layer = "wrs_season_Layer"
> wrs_season_shp = "D:\\model\\wrs_season.shp"
> Temp_mdb = "D:\\model\\Temp.mdb"
> ecoregions = "D:\\model\\Eco\\wwfecoregions\ecoregions.shp"
>
> t=string.Template("D:\\model\\Temp.mdb\\T$Num")
> p = string.Template('"PATH" = $Path')t
>
> # Process:
>
> print "Calculating row 1"
> gp.MakeFeatureLayer_management(wrs_season_shp, wrs_season_Layer,
> p.substitute(Path ='1'), Temp_mdb,)
> gp.TabulateArea_sa(wrs_season_Layer,"PR", ecoregions, "BIOME",
> t.substitute(Num = '1'), "0.01")
>
> print "Calculating row 2"
> gp.MakeFeatureLayer_management(wrs_season_shp, wrs_season_Layer,
> p.substitute(Path ='2'), Temp_mdb,)
> gp.TabulateArea_sa(wrs_season_Layer,"PR", ecoregions, "BIOME",
> t.substitute(Num = '2'), "0.01")
> print "finished
>
>
> #This process repeats for 200 paths each requiring a calculation and a
> separate table creation indicating which path they are calculating#
> The problem I had when making $Path a variable is it won't process the SQL
> statement any longer because of the quotes around it. The format has to stay
> in (' "PATH" = X')
> for it to ingest correctly, another way would be "\"PATH\" = 1" however the
> same problem arises when you try to turn the 1 into a variable.
>
> Any help would be much appreciated I would think I could just create a
> parallel array incrementing by 1 and just looping through for 233 paths?
> Thankyou,
> Lynn
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101209/b819beb9/attachment-0001.html>
More information about the Tutor
mailing list