How to generate automatically the name of output parameters in a python script tool?


I have some Python script tools in ArcGIS for Desktop.

I need to reproduce what all geoprocessing tools do when the first input parameter is introduced: autogenerate a workspace and basename for the outputs.

How can I do that?

Meaning of red cross icon next to Geoprocessing tool/model?


I am using ArcGIS 10.1 for Desktop.

When I double-click on the toolbox command line, it is not working and appears as a red cross symbol in command tool icon.

So please, what can I do?

How to work with shapefile with 110,000 points?


I have a very large shapefile. It has 110,000 parcels, represented as points.
I’m not trying to do anything too advanced with it. Here’s what I want to do:

  1. Join it with an Excel file, export it as a new shapefile (unless there’s an easier way to incorporate the joined attributes into a shapefile)
  2. Use the identity tool to group the parcels into census tracts
  3. Use the field calculator to create a Boolean variable of sorts. I just copy and paste one column into a new field, and turn a value into 1 and all other values into 0.

The computer I’m using right now has i7-3770 and 16 GB of RAM, so I don’t know why ArcMap 10.1 would not respond when I’m trying to do any of those things.

If there is a way for me to do those things listed above without crashing the software, I’d like to know. Thank you.

how manage mysql spatial polygons in parent child style


I want to store location-polygon data in a parent-child relation. I am using spatial data in MySQL and Google map for polygon.

Eg:

  1. World
    • 1.1 US
    • 1.2 China
    • 1.3 Japan
    • 1.4 South Africa
      • 1.4.1 Pretoria
      • 1.4.2 Cape Town
    • 1.5 India
      • 1.5.1 New Delhi
      • 1.5.2 Chennai

Table in mysql:

CREATE TABLE IF NOT EXISTS `geom` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `g` geometry DEFAULT NULL,
  `location` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)

My questions are:

  1. How can I identify India is the parent of New Delhi?

  2. How to get children of India?

Any spatial query?

Result Window in ArcGIS 10.1 is not Opening


I booted up ArcMap 10.1 today and found out the Results Window was not opening up.

Background info:

  • ArcMap is running through a virtualization program through at my company.
  • Similar issue has came up in the past but with the search window not showing up.
  • IT couldn’t figure out what caused the issue with the search windows not opening up so they uninstalled the virulization program cleared the cache associated with ArcGIS.
  • I noticed whenever I click on Geoprocessing->Results (I have also added in the results button through customization), the right edge in the following image blinks.
  • I noticed a windows update went through last night so that may be the culprit? Then again, how did the search windows get borked?

I’ve scoured stack-exchange/internet and could not find any info relating to this issue. Tools successfully run and I can view the history log as mentioned here but i really need to view the results window so I can rerun various tools again without filling out the parameters again.

Does anybody know of any registry keys/services that I can look into that that may need to be tweaked?

I don’t want to resort to IT since I know for a fact they will uninstall everything, in turn loosing all my defaults e.g. shortcut keys, toolbars, and document customization.

MultiLineString to separate individual lines using Python with GDAL/OGR, Fiona, Shapely


There are lots of MultiLineString features in a polyline shapefile. The problem is to split these lines into separate individual lines. There is a similar question with PostGIS, but I need to code in Python.

I have been planning to extract the geometry from each MultiLineString feature and create separate features and append a shpfile with those new features. Later, in the second pass, I would delete the MultiLineString object which is no more required as it is now split into its components. It will require reading data from original shpfile and appending the newly created features to a copy of the shpfile. Then the appended (copy) shpfile needs to be rid of the MultiLineString features. It seems cumbersome as I find no way to read and write the shapefile simultaneously.

There should be better ideas to do that. How to split these lines into separate individual lines using Python with OGR, Shapely, Fiona or Pyshp? A snippet of code to give an idea is below.

import fiona
from shapely.geometry import LineString

original_shpfile = fiona.open(path_to_road_network_shapefile)
with fiona.open(path_to_road_network_shapefile, 'a') as copy_shpfile:
    rec = original_shpfile.next()
    while rec:
        try:
            vertices_on_link = rec['geometry']['coordinates']
            LineString(vertices_on_link) #reconstruct the line from vertices
            #if multipart, 
            #has multiple lists within the list, 
            #one for each of the Linestring component. also throws AssertionError

        except AssertionError:
            number_of_parts = len(vertices_on_link) 
            for x in range(0,number_of_parts):
                part = rec
                part['geometry']['coordinates'] = vertices_on_link[x]
                copy_shpfile.write(part)
        rec = original_shpfile.next()

#in the next phase, delete each of the the MultiLineString features from the copy of the shapefile

ArcPy Empty Buffers


I have written an ArcPy script to process a DTM into a point feature class to be used in Landform classification and ranking. It successfully produces what I need most of the time.

Randomly the buffer polygon step produces an empty feature class. If I run the same process “by hand” it works. If I run the script again, or from a value just before it failed, it also works. The issue is not consistent, it may do it on the 3rd loop, or the 300th loop.

I’ve attempted to mitigate this issue by checking my delete variable statements (memory leak management), and by writing a get count followed by an “if” statement that runs a “compact”, “repair geometry”, “add spatial index”, “Delete the last buffer feature class”, and “re buffer”. But to no avail. The first part of the script is below.. Any ideas would be welcome..

import arcpy
import winsound

######## Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
from arcpy.sa import *

######## Script arguments
FolderLocation = "C:\Data\Basin\"
InRaster = "C:\Data\DEM\Basin1"
GDB = "C:\Data\Basin1.gdb"

LandForm = GDB+"\LandForm"
TempP = GDB+"\TempP"

TopVal = 1037
ProcessingVal = 772
BotVal = 150
Range = TopVal-BotVal
Range2 = ProcessingVal - BotVal
Range3 = Range2
print "There are: "+ str(Range) +" values in this raster. With: " +str(Range2) + " to process"
print " "

#### Naming Conventions
SingleValue = "s_"
BandValue = "b_"
CountValue = "r_"
LandFormIValue = "u_"
PNeigbours = "p_"
Frequency = "f_"
BufferName = "buf_"
MultiName ="m_"
IntName = "i_"
DisName = "d_"

MegaBuffCount = 0
MegaMultiCount = 0
MegaCount = ProcessingVal +1

while (MegaCount) > (BotVal):
    MegaCount = (MegaCount-1)
    ## Reclass Single Values
    SingleValueName = SingleValue + str(MegaCount) +".tif"
    SingleValueNamePath = FolderLocation + SingleValueName
    SingleValuePolygonName = SingleValue + str(MegaCount)
    SingleValuePolygonNamePath = GDB+"\"+SingleValuePolygonName
    SingleValueCountName = CountValue + str(MegaCount)+".tif"
    SingleValueCountNamePath = FolderLocation + SingleValueCountName
    LandFormIncrementName = LandFormIValue + str(MegaCount) +".tif"
    LandFormIncrementNamePath = FolderLocation + LandFormIncrementName

    RC1 = str(BotVal)
    RC2 = str(MegaCount -1)
    NODATA = "NODATA"
    RC3 = str(MegaCount)       
    RC4 = str(TopVal)
    Val = 1
    Equ = "{0} {1} {2}; {3} {4} {5}".format (RC1,RC2,NODATA,RC3,RC4,Val)
    print "Process Number: " + str(Range2) + "   Height Value: "+ str(MegaCount) + " Count Processed: " +str(int(Range3)- int(Range2))
    print "A: Raster S Single Band:" + str(Range2) + " Equ: " +str(Equ)
    Range = Range -1
    Range2 = Range2-1

    Raster = arcpy.sa.Reclassify(InRaster,"Value",Equ, "NODATA")
    Raster.save(SingleValueNamePath)

    ## To Poly
    arcpy.RasterToPolygon_conversion(SingleValueNamePath, SingleValuePolygonNamePath, "NO_SIMPLIFY", "Value")
    print "B: Conversion Polygon: "+ SingleValuePolygonNamePath

    ####### TEST DIAGONALS
    print "      B1: Processing Diagonals"
    BufferNearName = BufferName + str(MegaCount)
    BufferNearNamePath = GDB+"\" + BufferNearName
    MultiPartName = MultiName + str(MegaCount)
    MultiPartNamePath = GDB+"\" + MultiPartName
    IntersectName = IntName + str(MegaCount)
    IntersectNamePath = GDB+"\" + IntersectName
    DissolveName = DisName + str(MegaCount)
    DissolveNamePath = GDB+"\" + DissolveName

    #Spatial Ref: GDA 94 Z50
    sr = arcpy.SpatialReference(28350)

    arcpy.Buffer_analysis(SingleValuePolygonNamePath,BufferNearNamePath,"100 decimeters","FULL","ROUND","ALL","")
    bufcount = arcpy.GetCount_management(BufferNearNamePath)
    result_value = bufcount[0]
    buffercount = int(result_value)

    MegaBuffCount = MegaBuffCount + buffercount

    if buffercount == 0:
    print "DANGER!!!!!!!!"
        arcpy.Delete_management(BufferNearNamePath)
        arcpy.Compact_management(GDB)
        arcpy.RepairGeometry_management (SingleValuePolygonNamePath)
        arcpy.AddSpatialIndex_management(SingleValuePolygonNamePath,0)
        arcpy.Buffer_analysis(SingleValuePolygonNamePath,BufferNearNamePath,"100 decimeters","FULL","ROUND","ALL","")
        winsound.PlaySound("SystemHand", winsound.SND_ALIAS)

        print "      B2: Buffer Error: " +str(bufcount) +" polygons. This Processing run: " + str(MegaBuffCount)

        bufcount2 = arcpy.GetCount_management(BufferNearNamePath)
        result_value2 = bufcount2[0]
        buffercount2 = int(result_value2)

        if buffercount2 == 0:
            arcpy.Delete_management(BufferNearNamePath)
            arcpy.Delete_management(SingleValueNamePath)
            arcpy.Delete_management(SingleValuePolygonNamePath)
            winsound.PlaySound("SystemHand", winsound.SND_ALIAS)
            winsound.PlaySound("SystemHand", winsound.SND_ALIAS)
            STOP # Deliberate error

    else:
        print "      B2: Buffer: " +str(bufcount) +" polygons. This Processing run: " + str(MegaBuffCount)

    arcpy.MultipartToSinglepart_management(BufferNearNamePath,MultiPartNamePath)
    Multicount = arcpy.GetCount_management(MultiPartNamePath)
    Mulresult_value = Multicount[0]
    MulCount = int(Mulresult_value)
    MegaMultiCount = MegaMultiCount + MulCount

    print "      B3: Multi Part: " +str(Multicount) +" polygons. This Processing run: "+ str(MegaMultiCount)

Which parameter data type is used in the Integrate geoprocessing tool for ranking?


I’m trying to figure out which parameter data type is used in, for example, the Integrate geoprocessing tool.

It looks like this:

enter image description here

I’d like to use it in a geoprocessing tool I’m making, but can’t figure out which data type it is.

Thanks for any help!

Control geoprocessing results related to default data values calculated for null inputs


I am looking for information on Default data values for the different data types in ArcGIS. We are running a series of Overlay Route Events (Linear Referencing) tool operations. If any of the values from the two input source tables are null then the values in result table are some default data value. For example for Date field types that have null values in the input tables the values that getting populated in the Overlay operation result are ’12/30/1899 0:00:00′.

This is happening in a file geodatabase at ArcMap 10.1 and Windows Server 2008.

Does anyone have information on default data values for data types specifically in reference to geoprocessing? Any suggestions to get the null values to stay when the Overlay does it’s calc?

Field properties say allow null is yes.

I received word from Esri that this is a known bug in the tool NIM081760. I’d be interested in hearing of any workarounds.

nx_spatial does not read all shapefile features


I have a polyline shapefile for a road network. The roads are split at every intersection (node), e.g. if two roads intersect at one point, then they are split into four links(edges). So using the attribute table of the shapefile, I know this shapefile has 600 edges. But when the shapefile is read in nx_spatial, total edges found is only 497. I would like to know why it is missing other 103 road links (edges). Thanks

import nx_spatial as ns     
roads = ns.read_shp(path)   #path = path to polyline shapefile
roads.number_of_edges()     #output = 497

Hope these info helps: Windows7, Python 2.7 Anaconda 64bit, Eclipse. The problem is related to nx_spatial. But I could not create such tag for low reputation.

Question and Answer is proudly powered by WordPress.
Theme "The Fundamentals of Graphic Design" by Arjuna
Icons by FamFamFam