Script never finishes and throws no errors. Creates lock on file until restart?


I have a simple script that gets all layers in a gdb and uses them to clip a DEM. What’s happening though is it starts the clipping but never finishes and after killing the process I am unable to delete the file because of some lock on the file. Any thoughts/ideas on what’s causing this or how to fix it? I tried the exact parameters within arcmap with no issues and zippy performance. Any help / suggestion are greatly appreciated.

[EDIT Working code below]

for dirpath, dirnames, filenames in arcpy.da.Walk(clipLayers, datatype="FeatureClass", type="ALL"):
for filename in filenames:
    if "ENG_NAME" in [f.name for f in arcpy.ListFields(os.path.join(dirpath, filename))]:
        print "Clipping: ", filename
        arcpy.env.overwriteOutput = True
        arcpy.Clip_management(dem, "#", r"M:/Masks_Test.gdb/" + filename + "_Clip", os.path.join(dirpath, filename), "0", "ClippingGeometry")

ArcGIS Geoprocessing “None Type” Second time


I am trying to publish an ArcGIS geoprocessing service in 10.2 I have a script setup that will run multiple times through Pycharm, but when I run it in ArcGIS it will run once and return this error:

Traceback (most recent call last): File
“C:UsersDesktopgitGeoprocessingService.py”, line 477, in
main() File “C:UsersDesktopgitGeoprocessingService.py”, line 372, in main
cur) File “C:UsersDesktop/gitGeoprocessingService.py”, line 136, in value_query
results = cur.fetchall() File “C:Python27ArcGIS10.2libsite-packagespsycopg2extras.py”, line
81, in fetchall
res = super(DictCursorBase, self).fetchall() File “C:Python27ArcGIS10.2Libdecimal.py”, line 543, in new
m = _parser(value.strip()) TypeError: ‘NoneType’ object is not callable

Failed to execute (Script).

The script itself is 800 lines, but here is the query I have been running that errors out:

def value_query(id_field, id, value_fields, start_date, end_date, date_field, table, cur):
    query2 = "SELECT "
    for field in value_fields:
        query2 += "NULLIF({0}, '-999')::NUMERIC(6,2),".format(field)
    query2 += "{0} " 
            "FROM {1} " 
            "WHERE {2} = '{3}' AND {0} BETWEEN '{4}' AND '{5}' " 
            "ORDER BY {0} ASC;".format(date_field, table, id_field, id, start_date, end_date)
    #print "This is Query:"
    #print query
    arcpy.AddMessage("{0}".format(query2))
    cur.execute(query2)

    results = cur.fetchall()

    #print "These are value query results:nn {0}".format(results)
    return results

Like I said it runs once in ArcGIS then errors out. However, if I close Arc completely and run the exact same script again, it runs once then stops. I feel like there may be some sort of caching or something that Arc does, but am completely stumped.

Finding shortest cumulative route (i.e. best 'hub') between networked points


How do I find the shortest cumulative route (i.e. best ‘hub’) between networked points?

I have a dataset where some but not all of the points in the network connect to each other, however it is possible to go from any one point to another via the network. My problem is that these points have different attributes, such that I need to find the shortest cumulative route between the points in each group (i.e. the best ‘hub’ that overall anyone in those points can get to the quickest/shortest average distance from all the other points in the group), as well as the overall ‘hub’ for all the points.

I’m not sure how to do this in QGIS—-much less how to format my dataset for it, since it’s not a stereotypical road or transportation network—-or whether there is a better alternative with which to accomplish the analysis. The spatial distance between the points is actually irrelevant, because the ‘length’ component for distance is the number of nodes between points (i.e. going through point B to reach point C from point A is shorter than going through points D and E when traveling between A and B).

ArcGIS 10: Create an event linear layer from a point layer based on directionality


I have a point layer that reflects the speed limits and a line layer of the roads. The location of the speed sign indicates in which direction the speed limit applies.

How can I make linear event table on top of the road layer that reflects the speeds? So for each segment, return two speed attributes, one for each direction.

Speed/road layer

Is there a way to access the GeoProcessing tools in QGIS, in code


Is there a way to access the GeoProcessing tools in QGIS, in code? I want to find the Difference between two layers and make a new shapefile with the result.It can be manually done by selecting vector->GeoProcessing Tools->Difference. But how to do it in my code? (I use python)
Please help me to find a solution to this problem

Updating MXD layer definitionQuery in arcpy is very slow


The code segment below has been extracted from a larger project. In short, I have an MXD which I want to generate multiple PDFs based on different criteria. The code below works. It loops through each of the layers within the MXD and updates the definitionQuery and the results are fine. On my desktop, the part of the code that sets the definitionQuery takes about 2 seconds, but the published code on the server takes over 40 seconds. Since that bit of code is called for each item in layer_parameter_list, the time of the report jumps from about a minute to multiple minutes.

When I update the defintionQuery, does the MXD get written to the drive? Does it re-filter the data then? On the server, the scratch is on a shared drive which could explain why it is slower. What can I do to improve performance? Can I tell the MXD not to be written? If the re-filtering is occurring, can I disable that until all definitionQuerys have been updated for all layers?

def function_that_iterates_over_data_and_generates_pdf_pages_from_mxd(mxd, extent):
    layer_parameter_list = [
        # field 1,    field 2,  field 3
        ['Company1', 'Value X',    'Value 1'],
        ['Company1', 'Value Y',    'Value 2'],

        ['Company2', 'Value X',    'Value 1'],
        ['Company2', 'Value Y',    'Value 2'],
    ]

    layer_queries = [
        ['layer_1', """"FIELD_1"='{0}' and "FIELD_2"='{1}'""",
                    """"FIELD_1"='{0}'' and "FIELD_2"='{1}'"""],
        ['layer_2', """"FIELD_2"='{1}' and "FIELD_3"='{2}'""",
                    """"FIELD_2"='{1}'' and "FIELD_3"='{2}'"""],
        ['layer_3', """"FIELD_1"='{0}' and "FIELD_3"='{2}'""",
                    """"FIELD_1"='{0}'' and "FIELD_3"='{2}'"""],
    ]

    dfs = arcpy.mapping.ListDataFrames(mxd)

    lyr_dict = {}
    for df in dfs:
        # Take opportunity to zoom each Dataframe as we build our
        # dictionary
        df.extent = extent
        for lyr in arcpy.mapping.ListLayers(mxd, '', df):
            if lyr.isFeatureLayer or lyr.isServiceLayer:
                lyr_dict[lyr.name, df.name] = lyr

    for (page_number, query_parameters) in enumerate(layer_parameter_list):
        # this block takes ~2 seconds on my desktop, but 40+ seconds on the server
        for (dfi, df) in enumerate(dfs):
            for layer_query in layer_queries:
                criteria = layer_query[dfi + 1].format(*query_parameters)
                arcpy.AddMessage("Criteria: " + criteria)#this was the problem line
                lyr = lyr_dict[layer_query[0], df.name]
                lyr.definitionQuery = criteria

        file_name = 'Page_{0}'.format('%02s' % page_number)
        arcpy.mapping.ExportToPDF(mxd, file_name)

EDIT: added back in the AddMessage line which was the cause of the slow down.

Geoprocessing Tools on ArcGIS 10.2 and Visual Studio 2012 -issues


I am migrating one of the existing project (custom Geo-processing tool- class library project) source code which runs on ArcGIS 10 SP4 and Visual studio 2010. This is working fine. I am could run the project and able to add this tool in ArcTool box. Publish this as GP service and consumed in application.

I am moving this code to new machine which Windows 2012 server and ArcGIS 10.2 and Visual studio 2012. The source code is fetched from TFS and and code is built successfully after updating ArcGIS libraries to 10.2 When I run the project in VS2012 – class library (starting – ArcMap.exe with specific mxd document as input) break points are not hit.

After doing some research I have found that ESRI Link here I have to update ArcMap.exe.config file. After updating config file to use Framework 4.0 break points are set but not getting hit. Whenever I run the class library project MXD is opens, but the break points are not getting hit and not able to debug the code. Project properties in VS2012 is same as I used in VS2010 (checked Register COM Exception) and enabled debugging.

Question:
a) Why VS2012 is not hitting breaking points?
b) Dll is successfully built, but I am not seeing this custom tool box in “Add tool ” box in ArcTool box.

I am not sure what am missing or some changes in ArcGIS 10.2. Please help.

Extract aregular gride of points (x,y) values inside a polygon in arcgis10.2


This question may be frequently asked .But until know there is no clear answer .

I need to extract a regular grid of points inside a polygon .In every time i construct several polygons from the specified polygon and get the vertices that looks as net and convert it to excel file.

But know i need extract points ( x,y coordinates )regularly and save it to excel file.

Can any one has experience in arcgis 10.2 program help me to do that?

Looking for Python module to do lat lon calculations


I’m looking for a Python module that can provide some / all of the following services using latitude/longitude to define points:

Distance between two points
Point in polygon 
Distance along a multi-point path 
Identifier of closest point from a dict of points with identifiers 
Distance from a point to each point in a dict containing points with identifiers
etc

You get the idea… Any suggestions?

How can I GROUP BY linear spatial clusters with PostGIS?


I have a series of points in a horizontal line, arranged into discrete spatial clusters by the underlying data pattern. Here’s an example of what they look like:

enter image description here

How can I use PostGIS to group them spatially into the highlighted sets A, B and C?

This is a harder problem than it initially seemed to me. So far I’ve tried:

  • Using ST_X() to order them, then lag() to identify points between which there are gaps. Unfortunately this just groups the points into “gap” groups and “interior” groups.

  • Using convex hulls around arbitrary spatial thresholds. This both failed to separate all clusters and had the side effect of creating mid-cluster separations. (For future reference, this was a dumb idea.)

  • Using ST_GeoHash() to cluster them. This doesn’t accurately catch the linear nature of the geometry.

Any assistance greatly appreciated.

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