Ejemplo n.º 1
0
 def makeRingsFromDistances(self):
     ''' make geodesic rings from distance list '''
     # make a table for TableToEllipse
     fields = {'x': 'DOUBLE', 'y': 'DOUBLE', 'Range': 'DOUBLE'}
     inTable = self._makeTempTable("ringTable", fields)
     cursor = arcpy.da.InsertCursor(inTable, ['x', 'y', 'Range'])
     #self.center is a list of PointGeometry
     for i in self.center:
         pt = i.firstPoint
         for r in self.rangeList:
             cursor.insertRow([pt.X, pt.Y, r * 2])
     del cursor
     self.intermediateDataToDelete.append(inTable)
     outFeatures = os.path.join("in_memory", "outRings")
     arcpy.TableToEllipse_management(inTable, outFeatures, 'x', 'y',
                                     'Range', 'Range', self.distanceUnits,
                                     '#', '#', '#', self.sr)
     exp = r"!Range! / 2.0"
     arcpy.CalculateField_management(inTable, 'Range', exp, 'PYTHON_9.3')
     self.intermediateDataToDelete.append(outFeatures)
     self.ringFeatures = outFeatures
     return outFeatures
Ejemplo n.º 2
0
def tableToEllipse(inputTable, inputCoordinateFormat, inputXField, inputYField,
                   inputMajorAxisField, inputMinorAxisField,
                   inputDistanceUnits, outputEllipseFeatures,
                   inputAzimuthField, inputAzimuthUnits,
                   inputSpatialReference):
    '''
    inputTable - input table, each row will be a separate line feature in output
    inputCoordinateFormat - coordinate notation format of input vertices
    inputXField - field in inputTable for vertex x-coordinate, or full coordinate
    inputYField - field in inputTable for vertex y-coordinate, or None
    inputMajorAxisField -
    inputMinorAxisField - 
    inputDistanceUnits -
    outputEllipseFeatures - polyline feature class to create
    inputAzimuthField - field in inputTable of rotation of ellipse from north
    inputAzimuthUnits - angular units of azimuth (rotation)
    inputSpatialReference - spatial reference of input coordinates
    
    returns polygon ellipse feature class
    
    inputCoordinateFormat must be one of the following:
    * DD_1: Both longitude and latitude values are in a single field. Two values are separated by a space, a comma, or a slash.
    * DD_2: Longitude and latitude values are in two separate fields.
    * DDM_1: Both longitude and latitude values are in a single field. Two values are separated by a space, a comma, or a slash.
    * DDM_2: Longitude and latitude values are in two separate fields.
    * DMS_1: Both longitude and latitude values are in a single field. Two values are separated by a space, a comma, or a slash.
    * DMS_2: Longitude and latitude values are in two separate fields.
    * GARS: Global Area Reference System. Based on latitude and longitude, it divides and subdivides the world into cells.
    * GEOREF: World Geographic Reference System. A grid-based system that divides the world into 15-degree quadrangles and then subdivides into smaller quadrangles.
    * UTM_ZONES: The letter N or S after the UTM zone number designates only North or South hemisphere.
    * UTM_BANDS: The letter after the UTM zone number designates one of the 20 latitude bands. N or S does not designate a hemisphere.
    * USNG: United States National Grid. Almost exactly the same as MGRS but uses North American Datum 1983 (NAD83) as its datum.
    * MGRS: Military Grid Reference System. Follows the UTM coordinates and divides the world into 6-degree longitude and 20 latitude bands, but MGRS then further subdivides the grid zones into smaller 100,000-meter grids. These 100,000-meter grids are then divided into 10,000-meter, 1,000-meter, 100-meter, 10-meter, and 1-meter grids.
    
    inputAzimuthUnits must be one of the following:
    * DEGREES
    * MILS
    * RADS
    * GRAD
    
    inputDistanceUnits must be one of the following:
    * METERS
    * KILOMETERS
    * MILES
    * NAUTICAL_MILES
    * FEET
    * US_SURVEY_FEET
    '''
    try:
        env.overwriteOutput = True

        deleteme = []
        scratch = '%scratchGDB%'
        joinFieldName = "JoinID"

        if env.scratchWorkspace:
            scratch = env.scratchWorkspace

        inputSpatialReference = _checkSpatialRef(inputSpatialReference)

        copyRows = os.path.join(scratch, "copyRows")
        arcpy.CopyRows_management(inputTable, copyRows)
        deleteme.append(copyRows)
        originalTableFieldNames = _tableFieldNames(inputTable,
                                                   joinExcludeFields)
        addUniqueRowID(copyRows, joinFieldName)

        copyCCN = os.path.join(scratch, "copyCCN")
        arcpy.ConvertCoordinateNotation_management(copyRows, copyCCN,
                                                   inputXField, inputYField,
                                                   inputCoordinateFormat,
                                                   "DD_NUMERIC", joinFieldName,
                                                   inputSpatialReference)
        deleteme.append(copyCCN)

        #Table To Ellipse
        copyEllipse = os.path.join(scratch, "copyEllipse")
        arcpy.TableToEllipse_management(copyCCN, copyEllipse, "DDLon", "DDLat",
                                        inputMajorAxisField,
                                        inputMinorAxisField,
                                        inputDistanceUnits, inputAzimuthField,
                                        inputAzimuthUnits, joinFieldName,
                                        inputSpatialReference)
        deleteme.append(copyEllipse)

        #Polyline To Polygon
        polylineToPolygon(copyEllipse, joinFieldName, outputEllipseFeatures)

        #Join original table fields to output
        arcpy.AddMessage(
            "Joining fields from input table to output line features...")
        arcpy.JoinField_management(outputEllipseFeatures, joinFieldName,
                                   copyRows, joinFieldName,
                                   originalTableFieldNames)

        arcpy.DeleteField_management(outputEllipseFeatures, [joinFieldName])

        return outputEllipseFeatures

    except arcpy.ExecuteError:
        # Get the tool error messages
        msgs = arcpy.GetMessages()
        arcpy.AddError(msgs)
        print(msgs)

    except:
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]

        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(
            sys.exc_info()[1])
        msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"

        # Return python error messages for use in script tool or Python Window
        arcpy.AddError(pymsg)
        arcpy.AddError(msgs)

        # Print Python error messages for use in Python / Python Window
        print(pymsg + "\n")
        print(msgs)

    finally:
        if len(deleteme) > 0:
            # cleanup intermediate datasets
            if debug: arcpy.AddMessage("Removing intermediate datasets...")
            for i in deleteme:
                if debug: arcpy.AddMessage("Removing Temp Dataset: " + str(i))
                # Comment this next line to skip delete:
                arcpy.Delete_management(i)
        if debug: arcpy.AddMessage("Done")
            addRow.RingRadius = rd * 2.0
            addRow.RingID = y
            addRows.insertRow(addRow)
            x += 1
        y += 1
    del addRow
    del addRows
    del getRow
    del getRows

    results = arcpy.GetCount_management(tempTable)

    # build ellipses
    arcpy.AddMessage("Constructing " + str(results) + " ring features ...")
    arcpy.TableToEllipse_management(tempTable, outputRings, "POINT_X",
                                    "POINT_Y", "RingRadius", "RingRadius",
                                    distanceUnits, "#", "#", "#",
                                    inputCentersSR)

    # Join fields
    tempTableOIDFieldName = arcpy.Describe(tempTable).OIDFieldName
    ringOIDFieldName = arcpy.Describe(outputRings).OIDFieldName
    arcpy.JoinField_management(outputRings, ringOIDFieldName, tempTable,
                               tempTableOIDFieldName, ["Range", "RingID"])

    # Delete junk field
    arcpy.DeleteField_management(outputRings, "RingRadius")

    # create radials temp table
    if buildRadials == True:
        arcpy.AddMessage("Using " + str(numberOfRadials) + " radials ...")
        tempRadialTable = os.path.join(env.scratchWorkspace, "tempRadialTable")
Ejemplo n.º 4
0
env.workspace = 'in_memory\\'
env.addOutputsToMap = True
env.overwriteOutput = True

# save selections to temporary FC
select_name = 'raw_selected'
sql_where = ''#'"semi_major" > 0 AND "semi_major" < 100000'
# Filter out unreasonable error radius
raw_selected = arcpy.Select_analysis(inLayer, select_name, sql_where)

# build ellipses
ellipse_name = 'ellipse_temp'
ell_temp = arcpy.TableToEllipse_management(select_name, ellipse_name,
                "longitude","latitude",
                #"semi_major","semi_minor",
                "error_radius","error_radius",
                "METERS",
                "ellipse","DEGREES","feature_id",sr)

featList = []
# iterate through ellipses
for feat in featList:

    sql_where = "{0}{1}".format('"feature_id" = ', feat)
    arcpy.SelectLayerByAttribute_management('ellipse_temp', "NEW_SELECTION", sql_where)
    # Line to polygon
    poly_name = "{0}_{1}".format('ellipse',str(feat))
    ellPoly = arcpy.FeatureToPolygon_management('ellipse_temp', poly_name,
                        "","ATTRIBUTES", 'ellipse_temp')
    # Erase polygon over land
    erase_name = "{0}_{1}".format('erase', str(feat))