Example #1
0
    pass


try:
    if arcpy.CheckExtension("3D") == "Available":
        arcpy.CheckOutExtension("3D")
    else:
        raise LicenseError

    for root, dirs, files in os.walk(data):
        for file in files:
            if file.endswith(".shp"):
                inFeature = (os.path.join(root, file))
                outFeature = str(os.path.join(root, file)).replace(
                    ".shp", "") + "_en.shp"
                footprint = str(os.path.join(root, file)).replace(
                    ".shp", "") + "_foot.shp"
                print(inFeature)
                print(outFeature)
                arcpy.EncloseMultiPatch_3d(inFeature, outFeature, 0.05)
                arcpy.IsClosed3D_3d(outFeature)
                arcpy.AddZInformation_3d(outFeature, 'VOLUME')
                arcpy.MultiPatchFootprint_3d(outFeature, footprint)

except LicenseError:
    print("3D Analyst license is unavailable")
except arcpy.ExecuteError:
    print(arcpy.GetMessages(2))

print('Message: Script successfully done!')
Example #2
0
                                    data_type="Shapefile",
                                    workspace=arcpy.env.scratchFolder)

slr_temp3 = arcpy.CreateScratchName("temp3",
                                    data_type="Shapefile",
                                    workspace=arcpy.env.scratchFolder)

slr_temp4 = arcpy.CreateScratchName("temp4",
                                    data_type="Shapefile",
                                    workspace=arcpy.env.scratchFolder)

slr_temp5 = arcpy.CreateScratchName("temp5",
                                    data_type="Shapefile",
                                    workspace=arcpy.env.scratchFolder)

arcpy.MultiPatchFootprint_3d(multipatch, buildings)

# Add field allbuildings_footprints

arcpy.AddField_management(multipatch, "SLR", "Double")
arcpy.AddField_management(multipatch, "SLRarea", "Double")
arcpy.AddField_management(multipatch, "PerSLR3", "Double")
arcpy.AddField_management(multipatch, "area", "Double")

arcpy.AddField_management(buildings, "SLR", "Double")
arcpy.AddField_management(buildings, "SLRarea", "Double")
arcpy.AddField_management(buildings, "PerSLR3", "Double")
arcpy.AddField_management(buildings, "area", "Double")

buildings_fields = ["FID", "SLR", "SLRarea", "PerSLR3", "Area"]
def CreateGeometries(media_params, model_html=model_html_default):
    """Create geometries based on the model file provided or get center coordinates
       from dialog"""
       
    arcpy.AddMessage('Starting to create geometries...')
    
    classes = {'POINT': {'name': 'virtual_outcrops_point'},
               'POLYGON': {'name':'virtual_outcrops_polygon'}
               }
    
    # Construct feature classes
    for fc in classes:
        fc_path = classes[fc]['path'] = os.path.join(gdb, classes[fc]['name'])
        
        # Check if feature classes exist
        if not arcpy.Exists(classes[fc]['path']):
            arcpy.AddMessage('\nCreating {} feature class...'.format(fc))
            arcpy.CreateFeatureclass_management(gdb, os.path.basename(fc_path), fc,
                                                spatial_reference=sr_out)
            CreateFields(fc_path)
        
#     for some reason it wants an editing session, probably because it´s versioned and must be locked
    edit = arcpy.da.Editor(gdb)
    edit.startEditing(False, True)
    edit.startOperation()
    
    # Update urls for PDF and image, html for popup
    fields['url_img'][0] = media_params['Image']['url']
    fields['url_pdf'][0] = media_params['PDF']['url']
    fields['popup_html'][0] = model_html
    fields_list = fields.items()
    fields_keys = [x[0] for x in fields_list]
    fields_values = [x[1][0] for x in fields_list]
    
    if not model_model == "":
        arcpy.AddMessage('Model was specified.\nAttempting to fetch coordinates for footprint and centroid...')
        model_path = os.path.join('in_memory', '3D')
        footprint_path = os.path.join('in_memory', 'footprint')
        footprint_proj_path = os.path.join(temp_env, 'simple.shp') # Env for Project can't be in_memory
        simplify_path = os.path.join('in_memory', 'simple')
        
        # Import 3D file
        arcpy.Import3DFiles_3d(in_files=model_model,
                               out_featureClass=model_path,
                               spatial_reference=sr_in,
                               )
        
        # Convert to footprint and project to WGS84UTM33N
        arcpy.AddMessage('Model imported. Getting footprint...')
        arcpy.MultiPatchFootprint_3d(in_feature_class=model_path,
                                     out_feature_class=footprint_path)
        
        arcpy.AddMessage('Footprint calculated. Projecting...')
        arcpy.Project_management(in_dataset=footprint_path,
                                 out_dataset=footprint_proj_path,
                                 out_coor_system=sr_out,
                                 )
            
        arcpy.AddMessage('Projected. Simplifying...')
        arcpy.SimplifyPolygon_cartography(in_features=footprint_proj_path,
                                        out_feature_class=simplify_path,
                                        algorithm='POINT_REMOVE',
                                        tolerance=10)
        
        cursor_poly = arcpy.da.InsertCursor(classes['POLYGON']['path'], fields_keys+["SHAPE@"])  
        
        for row in arcpy.da.SearchCursor(simplify_path, ['SHAPE@', 'SHAPE@XY']):
            # Create centroid point
            centroid_point = row[1]
            
            cursor_poly.insertRow(fields_values + [row[0]])
    
    elif model_model == "":
        # 
        arcpy.AddMessage('No model.\nTaking coordinates from dialog...')
        centroid_coords = arcpy.Point(coords_long, coords_lat)
        
        centroid_geom = arcpy.PointGeometry(centroid_coords, sr_in)
        centroid_proj = centroid_geom.projectAs(sr_out)
        centroid_point = centroid_proj.firstPoint

    with arcpy.da.InsertCursor(classes['POINT']['path'], fields_keys+["SHAPE@"]) as cursor_pnt:
        cursor_pnt.insertRow(fields_values + [centroid_point])
    
    edit.stopOperation()
    edit.stopEditing(True)