George,

Python does a pretty good job of freeing you from data types. But you
still have to explicitly convert floating point values to strings in
order to concatenate them with the + operator.

This line makes the variable strY a float:

strY  = float(raw_input('Please enter latitude of lower left corner'))

I'm not sure what "raw_input" returns but you may be able to just get
rid of the float() if it returns a string. Otherwise, you can use
something like:

really_a_stringY = str(strY)

Or you can use:

origin = str(strX) + ' ' + str(strY)

One of the wanky things learning Python through the ArcGIS
geoprocessor is that it presents a confused model of variables. You
really don't learn Python when you just pump data in and out of the
geoprocessor. And if you come from a VBA background, Python almost
seems to work the way you want until it doesn't.

-Eric

=--=---=----=----=---=--=-=--=---=----=---=--=-=-
Eric B. Wolf                           720-334-7734






On Thu, May 5, 2011 at 7:43 PM, George Corea <[email protected]> wrote:
> When I run the script below in IDLE it gives the following output/
> errors
>
> Importing arcpy site package...
> Setting workspace...
> Z:\atGIS\training\Python_Alaska_Course\George\2
> Please enter  output polygon shapefile name, including .shp
> extensionggg.shp
> Please enter longitude of lower left corner15
> Please enter latitude of lower left corner20
> Traceback (most recent call last):
>  File "Z:\atGIS\training\Python_Alaska_Course\George
> \2\2_Create_Tiled_polygons.py", line 19, in <module>
>    origin = strX + ' ' + strY
> TypeError: unsupported operand type(s) for +: 'float' and 'str'
>
> -----------
>
> When I run it in ArcCatalog
> I
> mporting arcpy site package...
>
> Setting workspace...
>
> Z:\atGIS\training\Python_Alaska_Course\George\2
>
> Runtime error <type 'exceptions.EOFError'>: EOF when reading a line
>
> I am just learning python and can't figure out what is causing
> these ...
>
> [code]
> #Python script to create 24 map collars for 1:63,360 series quads
> #
> # import system module
> print 'Importing arcpy site package...'
> import arcpy,os
>
> #set workspace environment
> print 'Setting workspace...'
> myPath = os.getcwd()
> arcpy.env.workspace = myPath
> print myPath
>
> # Set output shapefile name:
> outPolygonTheme = raw_input('Please enter  output polygon shapefile
> name, including .shp extension')
>
> # Set the origin of the fishnet
> strX  = float(raw_input('Please enter longitude of lower left
> corner'))
> strY  = float(raw_input('Please enter latitude of lower left corner'))
> origin = strX + ' ' + strY
>
> #yaxis straight north:
> yAxisCoordinate = strX + ' ' + strY +'.5' #half a degree north of
> origin
>
>
> # Each map collar is .5 wide, 0.25 degrees high
> Width = '0.5'
> Height = '0.25'
>
> # Number of rows and columns
> nRows =  '4'
> nCols = '6'
>
> # Each output cell will be a polygon
> geometryType = 'POLYGON'
> print '\n Creating polygons in ',outPolygonTheme,'....'
> arcpy.CreateFishnet_management(outPolygonTheme, origin,
> yAxisCoordinate, Width, Height, nRows, nCols, '#', '#', '#',
> geometryType)
> print arcpy.GetMessage(2)
> print '\n Defining polygon theme coordsys as Geographic NAD27'
> Projection = 'GCS_NAD_1927.prj'
> arcpy.DefineProjection_management(outPolygonTheme, Projection)
>
> print 'All Done...Good Bye'
>
> [/code]

Reply via email to