Thursday, May 31, 2018

How to Calculate RGB Percent Using Python

I was working on a project recently, where marketing needed varying shades of the same color for an online map.  So, my boss and I wrote a python script that will give the RGB numbers for your input.

Using PyScriptor, this was my code:


def main():
    pass

if __name__ == '__main__':
    main()

import numpy as np
import arcpy

#This script will calculate a percentage of a RGB color.

red = arcpy.GetParameterAsText(0)
green = arcpy.GetParameterAsText(1)
blue = arcpy.GetParameterAsText(2)

percent = arcpy.GetParameterAsText(3)

rgb = [int(red),int(green),int(blue)]
pct = float(percent)

def lighter(color, percent):
    '''assumes color is rgb between (0, 0, 0) and (255, 255, 255)'''
    color = np.array(color)
    white = np.array([255, 255, 255])
    vector = white-color
    return color + vector * percent
arcpy.AddMessage(lighter(rgb, pct))


Load this script into your ArcToolbox in ArcMap, and then it can be used in any mxd.  When running, it will ask for your RGB and the percent that you want.

Here is a post about how to calculate sequential numbers in ArcMap using Field Calculator.

Happy GISing!
Lindsy Hales Bentley

Wednesday, May 23, 2018

Converting Microstation DTM into a GIS Surface

Here is how to convert a Microstation DTM into a GIS surface.
  1. Open a new blank .dgn.  Make sure to use the default 3d seed file from ESRI.  Set the coordinate system (If a dialog box pops up asking if you want to change units, do so).
  2. In the dgn, select the window tab and show the InRoads Explorer window.
  3. In the Inroads Explorer window Select File, Open, select the .dtm, and select open.  The open window will stay open, you need to hit close after the dtm has been loaded.
  4. Highlight the imported .dtm and select the Surface tab.  Inside the surface tab, select view surface tab, and then select surface elevations.
  5. In the surface elevation window, deselect elevation, and double click points.  Make sure points come across with a text font.
  6. Save settings and then save the dgn.
  7. Run the “CAD to Geodatabase” tool in ArcMap or Pro.  Select the dgn that you saved.  Assign the coordinate system in the tool. Run.
  8. The feature class created is an annotation feature class.  Use the “Feature to Point” tool to convert to a point feature.
  9. Double check to make sure elevation came across in attribute table.
  10. Run the “Natural Neighbor” tool found in the spatial analyst toolbox, sub toolbox Interpolation.  Use the point feature class, using the elevation field to calculate. 

Here is another post I wrote about Model Builder.

Happy GISing!
Lindsy Hales Bentley