ArcMap中如何实现矢量建筑物阴影效果?

ArcMap中如何实现矢量建筑物图层阴影效果?
已邀请:

刘峥 - ArcGIS多面手

赞同来自:

【解决办法】:
可以利用arcpy实现,参考链接:
http://gis.stackexchange.com/q ... is-de

参考代码:
import arcpy
import os
import math

def message(msg, severity=0):
# Adds a Message (in case this is run as a tool)
# and also prints the message to the screen (standard output)
#
print msg

# Split the message on n first, so that if it's multiple lines,
# a GPMessage will be added for each line
try:
for string in msg.split('n'):
# Add appropriate geoprocessing message
#
if severity == 0:
arcpy.AddMessage(string)
elif severity == 1:
arcpy.AddWarning(string)
elif severity == 2:
arcpy.AddError(string)
except:
pass

def main():
arcpy.env.overwriteOutput=True

# Read in parameters
inputFC = arcpy.GetParameterAsText(0)
outputFC = arcpy.GetParameterAsText(1)
heightfield = arcpy.GetParameterAsText(2) #Must be in the same units as the coordinate system!
azimuth = math.radians(float(arcpy.GetParameterAsText(3))) #Must be in degrees
altitude = math.radians(float(arcpy.GetParameterAsText(4))) #Must be in degrees

# Specify output field name for the original FID
origfidfield = ORIG_FID

# Get field names
desc = arcpy.Describe(inputFC)
shapefield = desc.shapeFieldName
oidfield = desc.oidFieldName

#Output
message(Creating output feature class %s ... % outputFC)
arcpy.CreateFeatureclass_management(
os.path.dirname(outputFC),
os.path.basename(outputFC),
'POLYGON', , , ,
desc.spatialReference if not arcpy.env.outputCoordinateSystem else )
arcpy.AddField_management(outputFC, origfidfield, LONG)
inscur = arcpy.InsertCursor(outputFC)

# Compute the shadow offsets.
spread = 1/math.tan(altitude) #outside loop as it only needs calculating once

count = int(arcpy.GetCount_management(inputFC).getOutput(0))
message(Total features to process: %d % count)

searchFields = ,.join([heightfield, oidfield, shapefield])
rows = arcpy.SearchCursor(inputFC, , , searchFields)

interval = int(count/10.0) # Interval for reporting progress every 10% of rows

# Create array for holding shadow polygon vertices
arr = arcpy.Array()
for r, row in enumerate(rows):
pctComplete = int(round(float(r) / float(count) * 100.0))
if r % interval == 0:
message(%d%% complete % pctComplete)
oid = row.getValue(oidfield)
shape = row.getValue(shapefield)
height = float(row.getValue(heightfield))

# Compute the shadow offsets.
x = -height * spread * math.sin(azimuth)
y = -height * spread * math.cos(azimuth)

# Initialize a list of shadow polygons with the original shape as the first
shadowpolys = [shape]

# Compute the wall shadows and append them to the list
for part in shape:
for i,j in enumerate(range(1,part.count)):
pnt0 = part
pnt1 = part[j]
if pnt0 is None or pnt1 is None:
continue # skip null points so that inner wall shadows can also be computed

# Compute the shadow offset points
pnt0offset = arcpy.Point(pnt0.X+x,pnt0.Y+y)
pnt1offset = arcpy.Point(pnt1.X+x,pnt1.Y+y)

# Construct the shadow polygon and append it to the list
[arr.add(pnt) for pnt in [pnt0,pnt1,pnt1offset,pnt0offset,pnt0]]
shadowpolys.append(arcpy.Polygon(arr))
arr.removeAll() # Clear the array so it can be reused

# Dissolve the shadow polygons
dissolved = arcpy.Dissolve_management(shadowpolys,arcpy.Geometry())[0]

# Insert the dissolved feature into the output feature class
newrow = inscur.newRow()
newrow.setValue(origfidfield, oid) # Copy the original FID value to the new feature
newrow.shape = dissolved
inscur.insertRow(newrow)

del row, newrow, shadowpolys, dissolved
del inscur, rows

if __name__ == __main__:
main()

要回复问题请先登录注册