# Convert python from arcpy.da.SearchCursor to work in 10.0

I am using code such as

for row in arcpy.da.SearchCursor(polyFC, ["[email protected]"], spatial_reference=SR): # create inner buffer polyBuff = row[0].buffer(buffNum * -1) # create hull rectangle to establish a rotated area of interest coordSplit = row[0].hullRectangle.split(") # collect corner coordinates coordList = arcpy.Array([arcpy.Point(coordSplit[0],coordSplit[1]),arcpy.Point(coordSplit[2],coordSplit[3]),arcpy.Point(coordSplit[4],coordSplit[5]),arcpy.Point(coordSplit[6],coordSplit[7]),arcpy.Point(coordSplit[0],coordSplit[1])]) # create lines from hull rectangle currentLines = [] for pointNum in range(0,4): arcpy.Array([coordList.getObject(pointNum),coordList.getObject(pointNum+1)]) hullRecLine = arcpy.Polyline(arcpy.Array([coordList.getObject(pointNum),coordList.getObject(pointNum+1)])) currentLines.append(hullRecLine) # compare first and second line to determine if first line is short or long firstLong = 0 if currentLines[0].length < currentLines[1].length: if shortboolean == 'true': firstLong = 0 else: firstLong = 1 if currentLines[0].length > currentLines[1].length: if shortboolean == 'true': firstLong = 1 else: firstLong = 0 # calculate number of points needed along short axis numPoints = int(math.floor(currentLines[firstLong].length/lineSpaceNum)) # create and join points to create parallel lines for point in range(0,numPoints+1): shortPoint1 = currentLines[firstLong].positionAlongLine(lineSpaceNum*point) shortPoint2 = currentLines[firstLong + 2].positionAlongLine(currentLines[firstLong + 2].length - (lineSpaceNum*point)) parallel = arcpy.Polyline(arcpy.Array([shortPoint1.centroid,shortPoint2.centroid]), SR) # intersect parallel lines with buffer parallelBuff = parallel.intersect(polyBuff,2) parallels.append(parallelBuff)

but this only works in ArcGIS 10.1 and newer. Is there a way to do the same thing but have it function in ArcGIS 10.0?

use the equivelant cursor without .da.

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000039000000

ex:

shapefieldname = arcpy.Describe(featureclass).ShapeFieldName sCur = arcpy.SearchCursor(featureclass, {where_clause}, {spatial_reference}, {fields}, {sort_fields}) for row in sCur: feature = row.getValue(shapefieldname) (do stuff)

The following fields will be added to the input. If the fields already exist, the field values are updated.

The Object ID of the closest near feature. If no near feature is found, the value will be -1.

The distance between the input and near feature. The value is in the linear unit of the input features coordinate system, or Meters when the Method parameter is set to GEODESIC and the input is in a geographic coordinate system. If no near feature is found, the value will be -1.

The catalog path to the feature class that contains the near feature. This field is only added to the output table if multiple Near Features are specified. If no near feature is found, the value will be empty string or null.

The following fields will be added to the input features if the Location parameter is checked ( location parameter set to LOCATION in Python). The field values are updated if the fields already exist. The unit of the values of the fields depend what method is selected on the Method parameter. If set to Planar , the value is in the linear unit of the input feature's coordinate system. If set to Geodesic , the value is in the geographic coordinate system associated with the input feature's coordinate system.

X-coordinate of the location on the near feature which is closest to the input feature. If no near feature is found, the value will be -1.

Y-coordinate of the location on the near feature which is closest to the input feature. If no near feature is found, the value will be -1.

The following field will be added to the input features if the Angle parameter is checked ( angle parameter set to ANGLE in Python). The field values are updated if the fields already exist.

Angle of the line at the FROM_X and FROM_Y location which connects the input features to the near feature. If no near feature is found or the near feature intersects the input feature, the value will be 0.

The values for NEAR_FID and NEAR_DIST will be -1 if no feature is found within the search radius.

Both input features and near features can be point, multipoint, line, or polygon.

The Near Features can include one or more feature classes of different shape types (point, multipoint, line, or polygon).

The same feature class or layer may be used as both input and near features. In this situation, the input feature being evaluated is excluded from the near features candidates to avoid all features being closest to themselves.

The input features can be a layer on which you have performed a selection. The selected features will be used and updated during the execution of the tool. The remaining features will have the values of the newly created fields (such as NEAR_FID and NEAR_DIST ) set to -1.

When more than one near feature has the same shortest distance from an input feature, one of them is randomly chosen as the nearest feature.

When using the Planar option for the Method parameter, the input features should be in a projection that is appropriate for distance measurement, such as an equidistant projection.

To visualize the FROM_X , FROM_Y , NEAR_X , and NEAR_Y locations, the output table can be used as input to the Make XY Event Layer or XY To Line tools.

## Example application

There is no built-in way to work with HTML in ArcGIS. However, Python scripting provides access to methods and functions that can be used to create and modify HTML documents. To integrate this HTML functionality with ArcGIS, embed a Python script tool into a model.

The following example performs spatial and attribute queries on a parcels layer and generates an HTML report detailing the attributes of a user-specified parcel and neighboring parcels. The HTML generation is performed within a Python script that is executed from the model.

## Automating Map Series Pages in ArcGIS Pro With Python

I was wondering if anyone has come across any documentation to access the Map Series Pages in ArcGIS Pro via ArcPy. I thought this would have been part of the mapping module. Can this be done, or is it something coming in future releases.?

by RebeccaStrauch_ _GISP

Thanks Rebecca, however those links don't seem to cover what I am looking for. I'm wondering how to access and export the pages in a Map Series. something similar to the functionality of the arcpy.mapping.datadrivenPages class.

by RebeccaStrauch_ _GISP

Hmm. so I guess this sums it up for now then.

Not real helpful on a time line or if they will be supported. but sounds like for know you are out of luck.

by DanPatterson_Re tired

Yes. it was promised for the PRO 1.2 releases (some workarounds given)

but now called map series ( but still can't find a definitive. yes. ddp is now map series. quote0

I suspect that the pdfdocument and associated materials is what you are looking for

I'm looking for a way to automate the export of each page in a map series to a png or jpeg. This is possible with data driven pages in ArcMap - but doesn't appear to be possible in Pro (1.4). From the docs:

" If you have a map series enabled and export to a format other than PDF (for example, JPG), you'll only generate a single page output file. If you want a JPG file for every page in the map series, you'll need to manually display and export each page. "

**Insert complaints and griping here**

I too am looking to automate jpg exports from a Map Series and so far have nothing (admittedly I have wasted my time on this in a while) The only workaround I can think of is:

1) instead of using map series, create the extents of your maps manually and bookmark them

2) in python, loop through your bookmarks (setting the extent of your maps) and then export each one as jpeg

This is just a thought, and I have not tested / investigated the feasibility of it. If you try it, please let me know how it turns out for you.

Hope they just update the Arcpy module to handle this properly in the fall release of ArcGIS Pro (1.5)

The ArcGIS Pro Python reference is organized into Get started, Geoprocessing and Python , ArcPy functions and classes, and ArcPy modules sections. These sections are both browsable and searchable.

### Get started

Python is a free, cross-platform, open source programming language. It's widely used and supported and is an integral part of ArcGIS.

This section covers several important topics for getting started with Python in ArcGIS Pro , including Python migration for ArcGIS Pro , Python in ArcGIS Pro , What is ArcPy?, ArcGIS API for Python , Python Package Manager, and Notebooks in ArcGIS Pro .

ArcPy and the ArcGIS API for Python are complementary libraries ArcPy allows you to use, automate, and extend desktop GIS, and the ArcGIS API for Python supports the same for Web GIS.

An example would be using ArcPy to manage local data, adding it as layers to a map and using geoprocessing tools to create outputs and service definition files. The ArcGIS API for Python could then be used to publish the definition files to the Web GIS, compose a web map, or share those layers with others.

### Geoprocessing and Python

Python can be used to automate the execution of geoprocessing tools as well as provide the ability to create your own geoprocessing tools, either as a script tool or a Python toolbox tool. Click to expand the Accessing geoprocessing tools node and find introductory topics for working with and understanding geoprocessing tools such as Using tools in Python. Click the Creating geoprocessing tools node to find topics on creating your own tools, such as What is a script tool? and What is a Python toolbox?

### ArcPy functions and classes

The ArcPy functions and ArcPy classes sections provide help topics for functions and classes. Functions and classes provide additional functionality to support Python -based workflows. For a list of functionality, see An overview of ArcPy functions and An overview of ArcPy classes. Additional functions and classes are found in several ArcPy modules.

## Python toolbox for OpenStreetMap data

My project is a Python toolbox. This is my first bigger coding project and it took me quite some time to code this toolbox. I learned a lot from the start point to this day. I changed this code hundreds of times, whenever I learned about new trick or method. This code works. I tested it with various datasets, fixed bugs or any syntax errors.

• The code ha some Polish names for: variable, functions etc.
• GUI is all Polish
• I started using Python about 3 months ago

What my code does:

Main purpose of this toolbox was to automate OpenStreetMap (OSM) data transformation from voivodeship shapefiles into country sized one, from which values were selected by their attributes to visualize features (for example, roads were selected and symbolized).

The code consists of three classes which are three scripts inside of my toolbox.

It is used in ArcGIS Pro to help non-programmer user to replicate my work.

Can someone who is more experienced than me in Python give me some useful advice?

## Populate field by field of a related table in python

Trying to figure this out but am having trouble understanding what I fundamentally need to do.

I have a one-to-many relationship class. The one is fire hydrant. the many is fire hydrant inspections.

They are related by a unique FacilityID.

Both tables have a column called "CurrentPosition", and both of those columns have the same domain.

I am trying to figure how to run a python script that will parse through the inspections table, find the most recent inspection (by the field InspectionDate), take the value found in that record for CurrentPosition, and write it to the CurrentPosition field of the HydrantTable.

I am planning on finalizing this and having it run as a nightly task so any inspections performed, the current position is updated on the hydrant table that night.

Does anyone have any suggestions or documentation I can look up? Anyone doing anything similar?

## 1 Answer 1

I don't have any experience with arcpy, so possibly some of this may be invalid.

Mostly the code is very good: It's concise it's clear enough what it does without lot's of documentation, and it has the documentation it needs.

Exactly what makes code "good" depends on how it's going to be used. This looks like a standalone utility you use at your work, so keeing it brief and easy to maintain is probably worth more that thoroughly documenting everything and enforcing type constraints. Not everything below will be applicable to you.

## 1 Answer 1

Modular division is a well-known concept to almost everyone who has done any programming. In my opinion delegating it to a is_divisible_by function is not needed and only introduces unnecessary overhead by generating an additional function call. It's not like you are ever going to use any other implementation than using modular division. Instead I would simply inline it.

While I am a fan of clear variable names, and PEP8 recommends against single letter variables, using n for a generic number (and i for a generic counting integer) is IMO acceptable and helps keeping lines short.

Your FACTORS variable is only needed for the order, since it is just the keys of the dictionary. Since Python 3.7 the order of dictionaries is guaranteed to be insertion order (implemented since CPython 3.6), so you also don't need it for the order if you are using a modern version of Python.

You have a spelling error in raindrops (but at least it is also present when calling it).

The convert function can be a bit simplified by using or .

You could also get rid of the dictionary altogether and just use a list of tuples:

Instead of having a lot of testcases, which takes a lot of manual typing to setup, group similar testcases together and use unittest.TestCase.subTest :

For successful test cases this reports as one test case, but if it fails the additional information passed as keyword arguments is shown (here purposefully broken by supplying the wrong expected output):

I recommend nesting dictionaries for your conversions. Usually if you have a long chain of elif comparisons to a string or number, you should use a dictionary.

You can store the first unit as the primary key, and then the second value is the key of the second unit. The values then all need to be a number that you can multiply by in order to perform the conversion. So to divide by 1000, instead the value to multiply by is 1/1000 . You could technically store functions to call in order to evaluate the conversions but just numbers is simpler.

This makes it easier to see if all of them are implemented, they're kept in neat rows so you can make sure none of the math seems off. Another advantage is that you can automatically generate a list of values to tell the user about.

Also you could now make sure that the user is typing in a valid key this way.

conversions[unit1][unit2] is just called in order to test whether the key exists and will raise an error if it doesn't so that the user will be told to enter new keys. I also added .lower() so that if the user inputs CM , Cm or even cM they'll all be converted to cm to match the key.

I recommend wrapping the number input similarly, as it prevents errors later.

Now when it comes to the actual logic, it's really quite simple since both values are already prepared: