本文整理汇总了Python中arcpy.MakeFeatureLayer_management方法的典型用法代码示例。如果您正苦于以下问题:Python arcpy.MakeFeatureLayer_management方法的具体用法?Python arcpy.MakeFeatureLayer_management怎么用?Python arcpy.MakeFeatureLayer_management使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arcpy
的用法示例。
在下文中一共展示了arcpy.MakeFeatureLayer_management方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getClosestSegment
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import MakeFeatureLayer_management [as 别名]
def getClosestSegment(point, segments, maxdist):
arcpy.Delete_management('segments_lyr')
arcpy.MakeFeatureLayer_management(segments, 'segments_lyr')
arcpy.SelectLayerByLocation_management ("segments_lyr", "WITHIN_A_DISTANCE", point, maxdist)
#Go through these, compute distances, probabilities and store them as candidates
cursor = arcpy.da.SearchCursor('segments_lyr', ["OBJECTID", "SHAPE@"])
sdist = 100000
candidate = ''
for row in cursor:
#compute the spatial distance
dist = point.distanceTo(row[1])
if dist <sdist:
sdist=dist
candidate = row[0]
del row
del cursor
#print str(candidates)
return candidate
示例2: getSegmentInfo
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import MakeFeatureLayer_management [as 别名]
def getSegmentInfo(segments):
"""
Builds a dictionary for looking up endpoints of network segments (needed only because networkx graph identifies edges by nodes)
"""
if arcpy.Exists(segments):
cursor = arcpy.da.SearchCursor(segments, ["OBJECTID", "SHAPE@"])
endpoints = {}
segmentlengths = {}
for row in cursor:
endpoints[row[0]]=((row[1].firstPoint.X,row[1].firstPoint.Y), (row[1].lastPoint.X, row[1].lastPoint.Y))
segmentlengths[row[0]]= row[1].length
del row
del cursor
print "Number of segments: "+ str(len(endpoints))
#prepare segment layer for fast search
arcpy.Delete_management('segments_lyr')
arcpy.MakeFeatureLayer_management(segments, 'segments_lyr')
return (endpoints,segmentlengths)
else:
print "segment file does not exist!"
示例3: getAOI
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import MakeFeatureLayer_management [as 别名]
def getAOI(prod_db):
# Set workspace
arcpy.env.workspace = prod_db
# Get MetaDataA fc
meta_fc = getFC(prod_db, "MetaDataA", NAUT_FDS)
if meta_fc:
# Make feature layer where FCSUBTYPE = M_NSYS
where = "FCSUBTYPE = 35"
arcpy.MakeFeatureLayer_management(meta_fc, "meta_lyr", where)
# Dissolve layer into one feature
arcpy.AddMessage("\tDissolving area of interest into one feature")
aoi = "in_memory\\aoi"
arcpy.Dissolve_management("meta_lyr", aoi, multi_part="SINGLE_PART")
arcpy.MakeFeatureLayer_management(aoi, "aoi")
return "aoi"
else:
raise ex("MetaDataA feature class not found in " + prod_db)
示例4: copyFlowlines
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import MakeFeatureLayer_management [as 别名]
def copyFlowlines(self, in_drainage_line, path_database, list_uniqueID):
"""Create copies of flowlines based on the layer query definitions"""
# make a feature layer for query selection
name_lyr = "flowlines"
arcpy.MakeFeatureLayer_management(in_drainage_line, name_lyr)
'''Create the query expression for line features with matching records in the flat table'''
expression_base = self.name_ID + " IN ("
count = len(list_uniqueID)
counter = 1
for each_ID in list_uniqueID:
if counter == count:
expression_base = expression_base + str(each_ID) + ")"
else:
expression_base = expression_base + str(each_ID) + ", "
counter += 1
for each_key in self.layer_minScale_maxScale_query.keys():
out_copy = os.path.join(path_database, "Flowline_"+each_key)
pars = self.layer_minScale_maxScale_query[each_key]
query = pars[2]
expression = expression_base
if query is not None:
expression = expression_base + "AND " + query
arcpy.SelectLayerByAttribute_management(name_lyr, "NEW_SELECTION", expression)
arcpy.CopyFeatures_management(name_lyr, out_copy)
arcpy.AddIndex_management(out_copy, self.name_ID, self.name_ID, "UNIQUE", "ASCENDING")
return
示例5: create_feature_layer
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import MakeFeatureLayer_management [as 别名]
def create_feature_layer(ds, sql, name="layer"):
""" creates a feature layer object """
if arcpyFound == False:
raise Exception("ArcPy is required to use this function")
result = arcpy.MakeFeatureLayer_management(in_features=ds,
out_layer=name,
where_clause=sql)
return result[0]
#----------------------------------------------------------------------
示例6: maskCoastlineConflicts
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import MakeFeatureLayer_management [as 别名]
def maskCoastlineConflicts(prod_db, desktop_fldr):
arcpy.AddMessage("\tMasking coastline and bridges")
# Subtype field used in where clause to access bridges in CulturalFeaturesA
subtype_fld = arcpy.AddFieldDelimiters(prod_db, "FCSubtype")
# Get subtype of Bridge
bridge = "5"
# Define spatial reference
sr = arcpy.SpatialReference(4326)
# Get CoastlineL and CulturalFeaturesA layers
coastlinel_fc = getFC(prod_db, "CoastlineL", NAUT_FDS)
culturalfeaturesa_fc = getFC(prod_db, "CulturalFeaturesA", NAUT_FDS)
# Only continue if CoastlineL and CulturalFeaturesA layers are in the TOC
if coastlinel_fc != "" and culturalfeaturesa_fc != "":
# Make feature layer form CoastlineL
arcpy.MakeFeatureLayer_management(coastlinel_fc, "coastlinel_lyr")
# Make feature layer of bridge features
where = subtype_fld + " = " + bridge
arcpy.MakeFeatureLayer_management(culturalfeaturesa_fc, "bridges", where)
# Check if there are any bridge features in the layer
if int(arcpy.GetCount_management("bridges").getOutput(0)) > 0:
# Run Intersecting Layers Mask GP tool to create mask poly where coastline intersect bridges
mask_fc = os.path.join(prod_db, CARTO_FDS, "MASK_CoastlineL")
arcpy.IntersectingLayersMasks_cartography("bridges", "coastlinel_lyr", mask_fc, REF_SCALE, sr, "0.01 POINTS")
return
示例7: create_layer_file
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import MakeFeatureLayer_management [as 别名]
def create_layer_file(service_info, service_name, layer_source, output_folder):
"""
write out a layer file from service renderer information, providing
:param service_info: json (to extract the drawingInfo from)
:param service_name: String
:param layer_source: String path to file
:param output_folder: String path
"""
try:
render_info = {"drawingInfo": {"renderer": {}}}
if service_info.has_key('drawingInfo'):
render_info["drawingInfo"]['renderer'] = service_info.get('drawingInfo').get('renderer')
render_file = os.path.join(output_folder, service_name + "_renderer.txt")
with open(render_file, 'w') as r_file:
json.dump(render_info, r_file)
output_msg("Yar! {0} Service renderer stashed in '{1}'".format(service_name, render_file))
layer_file = os.path.join(output_folder, service_name + ".lyr")
output_msg("Sketchin' yer layer, {}".format(layer_file))
layer_temp = arcpy.MakeFeatureLayer_management(layer_source, service_name)
arcpy.SaveToLayerFile_management(in_layer=layer_temp, out_layer=layer_file, is_relative_path="RELATIVE")
lyr_update = arcpy.mapping.Layer(layer_file)
lyr_update.updateLayerFromJSON(render_info)
lyr_update.save()
output_msg("Stashed yer layer, {}".format(layer_file))
else:
output_msg("Gaar, no renderer t' sketch from, so no layer file fer ya")
except Exception, e:
output_msg(str(e), severity=1)
output_msg("Failed yer layer file drawin'")
示例8: setEdgeHierarchy
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import MakeFeatureLayer_management [as 别名]
def setEdgeHierarchy(fcs, aoi, hier_field):
""" sets the hierarchy of all features touching the aoi to 0"""
arcpy.AddMessage("Setting hierarcy for edge features")
for fc in fcs:
fields = [f.name for f in arcpy.ListFields(fc)]
if hier_field in fields:
lyr = arcpy.MakeFeatureLayer_management(fc, "layera")
arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", aoi)
arcpy.CalculateField_management(lyr, hier_field, "0")
arcpy.Delete_management(lyr)
示例9: setUp
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import MakeFeatureLayer_management [as 别名]
def setUp(self):
# Load layers
self.demand_polygon_fl = arcpy.MakeFeatureLayer_management(r"../sample_data/demand_polygon.shp").getOutput(0)
self.facility_service_areas_fl = arcpy.MakeFeatureLayer_management(
r"../sample_data/facility_service_areas.shp").getOutput(0)
self.demand_point_fl = arcpy.MakeFeatureLayer_management(r"../sample_data/demand_point.shp").getOutput(0)
self.facility2_service_areas_fl = arcpy.MakeFeatureLayer_management(
r"../sample_data/facility2_service_areas.shp").getOutput(0)
self.facility_point_fl = arcpy.MakeFeatureLayer_management(
r"../sample_data/facility.shp").getOutput(0)
self.facility2_point_fl = arcpy.MakeFeatureLayer_management(
r"../sample_data/facility2.shp").getOutput(0)
# Load 'golden' coverages
# Read the coverages
with open("valid_coverages/partial_coverage1.json", "r") as f:
self.partial_coverage = json.load(f)
with open("valid_coverages/binary_coverage_polygon1.json", "r") as f:
self.binary_coverage_polygon = json.load(f)
with open("valid_coverages/binary_coverage_point1.json", "r") as f:
self.binary_coverage_point = json.load(f)
with open("valid_coverages/partial_coverage2.json", "r") as f:
self.partial_coverage2 = json.load(f)
with open("valid_coverages/binary_coverage_polygon2.json", "r") as f:
self.binary_coverage_polygon2 = json.load(f)
with open("valid_coverages/binary_coverage_point2.json", "r") as f:
self.binary_coverage_point2 = json.load(f)
with open("valid_coverages/serviceable_demand_polygon.json", "r") as f:
self.serviceable_demand_polygon = json.load(f)
with open("valid_coverages/serviceable_demand_point.json", "r") as f:
self.serviceable_demand_point = json.load(f)
with open("valid_coverages/traumah_coverage.json", "r") as f:
self.traumah_coverage = json.load(f)
示例10: cartoLimits
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import MakeFeatureLayer_management [as 别名]
def cartoLimits(aoi, prod_db, desktop_fldr):
# Subtype field used in where clause to filter inputs to Model
subtype_fld = arcpy.AddFieldDelimiters(prod_db, "FCSubtype")
# Make feature layer of aoi
arcpy.MakeFeatureLayer_management(aoi, "aoi")
# Convert AOI to polyline
aoi_line = os.path.join(arcpy.env.scratchGDB, "aoi_line")
arcpy.FeatureToLine_management("aoi", aoi_line)
arcpy.MakeFeatureLayer_management(aoi_line, "aoi_line")
# Get list of input feature classes, subtypes, and cart limit feature classes
inputs = [["DangersA", [], "DangersA_L"],
["DepthsA", ["5", "10", "15"], "DepthsA_L"],
["IceFeaturesA", [], "IceA_L"],
["MilitaryFeaturesA", [], "MilitaryA_L"],
["NaturalFeaturesA", ["1", "20", "35"], "NaturalA_L"],
["OffshoreInstallationsA", [], "OffshoreA_L"],
["PortsAndServicesA", ["5", "10", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "80"], "PortsA_L"],
["RegulatedAreasAndLimitsA", ["1", "5", "10", "15", "20", "30", "40", "50", "60", "65", "70", "75", "85", "95", "105", "110", "115"], "RegulatedA_L"],
["SeabedA", ["15"], "SeabedA_L"],
["TracksAndRoutesA", ["1", "5", "10", "15", "20", "25", "40", "45", "70"], "TracksA_L"]]
# Set workspace
arcpy.env.workspace = prod_db
# Get CoastlineA and CloastlineL layers
coastlinea_fc = getFC(prod_db, "CoastlineA", NAUT_FDS)
arcpy.MakeFeatureLayer_management(coastlinea_fc, "CoastlineA")
coastlinel_fc = getFC(prod_db, "CoastlineL", NAUT_FDS)
arcpy.MakeFeatureLayer_management(coastlinel_fc, "CoastlineL")
# Loop through list of inputs
for data in inputs:
# Get full paths to data
input_fc = getFC(prod_db, data[0], NAUT_FDS)
output_fc = getFC(prod_db, data[2], CARTO_FDS)
if input_fc != "" and output_fc != "":
# Check if there are subtypes, if there are, write where clause
where = ""
if len(data[1]) > 0:
where = subtype_fld + " = "
where = where + (" OR " + subtype_fld + " = ").join(data[1])
# Remove single quotes that get added to beginning and end of where clause
where = where.replace("'", "")
# Select features in where clause
arcpy.MakeFeatureLayer_management(input_fc, "in_lyr", where)
# Only run Generate Cartographic Limits model if layer has features
if int(arcpy.GetCount_management("in_lyr").getOutput(0)) > 0:
arcpy.AddMessage("\t\t" + data[2])
arcpy.GenerateCartographicLimits_nautical("in_lyr", "CoastlineL; CoastlineA; aoi_line", output_fc)
return
示例11: chart
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import MakeFeatureLayer_management [as 别名]
def chart(x, out_file='c:\\temp\\chart.jpg', texts={}, template=None, resolution=95, openit=True):
"""Create and open a map (JPG) showing x and return path to the figure path.
Required:
x -- input feature class, raster dataset, or a layer
Optional:
out_file -- path to output jpeg file, default is 'c:\\temp\\chart.jpg'
texts -- dict of strings to include in text elements on the map (by name)
template -- path to the .mxd to be used, default None points to mxd with
a single text element called "txt"
resolution -- output resolution in DPI (dots per inch)
openit -- if True (default), exported jpg is opened in a webbrowser
Example:
>>> chart('c:\\foo\\bar.shp')
>>> chart('c:\\foo\\bar.shp', texts = {'txt': 'A Map'}, resolution = 300)
"""
todel = []
import re
if template is None: template = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'chart.mxd')
if not re.findall(".mxd", template, flags=re.IGNORECASE): template += ".mxd"
if not re.findall(".jpe?g", out_file, flags=re.IGNORECASE): out_file += ".jpg"
mxd = arcpy.mapping.MapDocument(template)
if not arcpy.Exists(x):
x = arcpy.CopyFeatures_management(x, arcpy.CreateScratchName('tmp', workspace = 'in_memory')).getOutput(0)
todel = [x]
dtype = arcpy.Describe(x).dataType
df = arcpy.mapping.ListDataFrames(mxd)[0]
lr = "chart" + tstamp(tf = "%H%M%S")
if arcpy.Exists(lr) and arcpy.Describe(lr).dataType in ('FeatureLayer', 'RasterLayer'):
arcpy.Delete_management(lr)
if "raster" in dtype.lower():
arcpy.MakeRasterLayer_management(x, lr)
else:
arcpy.MakeFeatureLayer_management(x, lr)
lyr = arcpy.mapping.Layer(lr)
arcpy.mapping.AddLayer(df, lyr)
# try to update text elements if any requested:
for tel in texts.iterkeys():
try:
texel = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", tel)[0]
texel.text = str(texts[tel])
except Exception, e:
arcpy.AddMessage("Error when updating text element " + str(tel) + ": "+ str(e))