Select to view content in your preferred language

Updating Python Script arcgisscripting $$rowmap, $$colmap // Generating a random pattern raster

1445
2
10-29-2022 12:50 AM
AK_Mapplications
New Contributor

Issue

I'd like to update an Esri toolbox Python script that calls on ArcGIS 9.3 geoprocessor GRID variables $$rowmap and $$colmap to create a random raster within specific parameters.

I hope to update the existing Python script do something such as:

create a cell every 10 meters of X and Y with a randomness of 10 (Standard Deviation of 10) which would have looked similar to the text below:

pattern = focalmax(con( ($$rowmap mod int(normal() * 10 + 10) eq 0)and ($$colmap mod int(normal() * 10 + 10) eq 0),255,0))

 

akmapplications_0-1667028223326.png

 

What is the the alternative to $$rowmap and $$colmap? 

Context

I want to create bump maps in Arc using the Esri bump map toolbox, released in 2010.  Further explanation on the bump map can also be found from an early Esri UC proceeding.

The scripts used the ArcGIS 9.3 geoprocessor GRID variables $$rowmap and $$colmap within a Python script that was used in ModelBuilder. Support for these commands was removed starting in ArcGIS 10.0 (so I've read). Although I can import the arcgisscripting geoprocessor 9.3 object without issue and the rest of the script still functions, the offending line 47 in BumpMapPart1.py is below (entire script attached as text file). I don't need a GRID file, I'd be happy with other raster formats.

@DanPatterson , @DanPatterson_Retired  - Perhaps this is best solved with NumPy? I think your solution on this thread may be the answer, but you link to another thread that is now broken.

I read a decade old post about Flow Accumulator, but that seems quite complicated to replace just one line of code.

 

# BumpMapPart1.py
# Description: 
# This script generates point patterns 
# based on the user inputs in a given area (extent)  
# Requirements: Spatial Analyst Extension
# Author: Rajinder Nagi, ESRI
# Date: July 20, 2009
# Revised date: Oct 9, 2009

# Import sys,system modules
import sys, string, os, arcgisscripting
import locale as LOCALE

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

ws = gp.workspace
scratch = gp.ScratchWorkspace


# Check out Spatial Analyst extension license
    
gp.CheckOutExtension("Spatial")

VegMask = gp.GetParameterAsText(0)
ConeOrDome = gp.GetParameterAsText(1)
Density = gp.GetParameterAsText(2)
Radius = gp.GetParameter(3)
ht = gp.GetParameterAsText(4)
PointPattern = gp.GetParameterAsText(5)

Randomness = "10" # standard deviation

# if you provide density as 20m and randomness of 1, then it will create a point(randomness = 1) 
# at every 20 m of x and y.

try:
    # this will generate random points based on density in a given extent 
    InputCellSize = ""
    if InputCellSize == "":
        cellsize = (Radius*2/11.0)
    else:
        cellsize = InputCellSize
    # Set local variables
    gp.AddMessage ("Generating point pattern...")
    InExpression = "con($$rowmap mod int(normal() * "+ Randomness +" + "+ Density +") == 0 and $$colmap mod int(normal() * "+ Randomness +" + "+ Density +")  == 0,255)"
  
    # Process: MapAlgebraStatement
    gp.CellSize = cellsize
    gp.Mask = VegMask
    #gp.Extent = VegMask
    gp.Extent = "'"+VegMask+"'" ## to deal with spaces in workspace
    gp.SingleOutputMapAlgebra_sa(InExpression, PointPattern)
    gp.AddMessage ("Point pattern generated...")

except Exception as e:
    # If an error occurred while running a tool, then raise the error.
    gp.AddError(e.message)
    raise arcgisscripting.ExecuteError

 

 

Also @BrittaSchroeder
0 Kudos
2 Replies
Luke_Pinner
MVP Regular Contributor

You can replace gp.SingleOutputMapAlgebra_sa(InExpression, PointPattern) with arcpy.gp.SingleOutputMapAlgebra_sa(InExpression, PointPattern) but you also have to change all the other gp.etc... to the appropriate arcpy. or arcpy.env or arcpy.management etc... and there's a lot of correcting case required as the arcgisscripting gp object wasn't case sensitive but arcpy is.  e.g. gp.CellSize or gp.cellsize needs to become arcpy.env.cellSize

0 Kudos
Luke_Pinner
MVP Regular Contributor

Here's a version (of just the Scripts, the rest of the tool you need from here) that works in ArcMap 10.8. Note the model doesn't work in ArcGIS Pro as it doesn't iterate.

0 Kudos