def main(): # Process parameters BFE_file = arcpy.GetParameterAsText(0) channel_filename = arcpy.GetParameterAsText(1) channel_river_field = arcpy.GetParameterAsText(2) channel_reach_field = arcpy.GetParameterAsText(3) outfilename = arcpy.GetParameterAsText(4) convert_to_CAD = arcpy.GetParameterAsText(5) # Import RAS data from csv arcpy.AddMessage('Importing BFEs from ' + BFE_file) rs = import_BFE_from_CSV(BFE_file) # Process RAS data and calculate BFE locations arcpy.AddMessage('Calculating BFE locations...') rs.sort_all() rs.calc_all_reach_lengths() rs.calc_all_BFEs() arcpy.AddMessage('Done.') # Create BFEs in GIS create_BFEs = CreateBFEs(rs, channel_filename, channel_river_field, channel_reach_field, outfilename) create_BFEs.set_BFE_dimensions(50, True, 25) create_BFEs.create_BFEs() # Convert BFEs to CAD if convert_to_CAD == 'true': arcpy.AddMessage('Exporting to CAD') arcpy.ExportCAD_conversion(outfilename, 'DWG_R2010', outfilename[:-3] + 'dwg') time.sleep(3)
def Raster_to_Contour(): #Set up working environment arcpy.env.workspace = r"C:\GIS Automation\Florida Project\data" #Reproject Raster arcpy.ProjectRaster_management( "03meter_smoothed.tif", "03meter_smoothed_reproject.tif", "NAD 1983 StatePlane Florida East FIPS 0901 (US Feet).prj", "NEAREST") #Build pyramids for Raster #arcpy.BuildPyramids_management("f19_resample_2_reproject.tif", "-1", "NONE", "NEAREST", "NONE", "75") #Convert Raster unit from meter to feet outRas = Raster("03meter_smoothed_reproject.tif") * 3.28 outRas.save("03meter_smoothed_feet.tif") #Extract Contours arcpy.sa.Contour("03meter_smoothed_feet.tif", "contours_feet_1.shp", 1, 0) #Export to CAD input_feature = "contours_feet_1.shp" output_type = "DWG_R2013" output_file = "Contours_feet_1_crash.dwg" try: arcpy.ExportCAD_conversion(input_feature, output_type, output_file) except: print arcpy.GetMessages()
def exportTopoTINDXF(self, outFolder): """exports dxf file (and SHP files) containing tin components of topo tin in same folder as gdb""" from os import path, makedirs arcpy.CheckOutExtension("3D") arcpy.env.workspace = arcpy.Describe(self.filename).path topoTINs = arcpy.ListDatasets("TIN*", "Tin") topoTIN = topoTINs[0] outfile = path.join(outFolder, "TopoTin") + ".dxf" memTinPoints = "in_memory//tin_points" memTinLines = "in_memory//tin_lines" memTinArea = "in_memory//tin_area" # TODO Do actual breaklines need to be pulled into their own layer? listTINComponents = [memTinPoints, memTinLines, memTinArea] for item in listTINComponents: if arcpy.Exists(item): arcpy.Delete_management(item) arcpy.TinNode_3d(topoTIN, memTinPoints) arcpy.TinEdge_3d(topoTIN, memTinLines, "DATA") arcpy.TinDomain_3d(topoTIN, memTinArea, "POLYGON") # TODO Convert Line Type from eSRI code?? arcpy.ExportCAD_conversion(listTINComponents, "DXF_R2007", outfile) return outfile
def export_cad(): """Exports the feature class as a CAD drawing file Returns: None """ folder = 'cad' name = get_dataset_filename() # Create a cad folder in the temp directory if it does not exist temp_working_folder = os.path.join(temp_workspace, folder) create_folder(temp_working_folder, True) # Export the shapefile to the folder source = staging_feature_class destination = os.path.join(temp_working_folder, name + ".dwg") # Export the drawing file logger.debug('Exporting to DWG file from "' + source + '" to "' + destination + '"') arcpy.ExportCAD_conversion(source, "DWG_R2000", destination, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "") # Publish the zipfile to the download folder publish_file(temp_working_folder, name + ".dwg", "cad")
def transG(gauss, utm, krrgjsh): name = coord["2"] + "_2_" + coord["1"] + "_7parameters" name2 = coord["1"] + "_2_" + coord["3"] + "_7parameters" arcpy.CADToGeodatabase_conversion( path, os.path.join(workingDir, "tempFolder\\test.gdb"), coord["2"], 1000, gauss) arcpy.CreateFeatureDataset_management( os.path.join(workingDir, "tempFolder\\test.gdb"), coord["1"], utm) arcpy.CreateFeatureDataset_management( os.path.join(workingDir, "tempFolder\\test.gdb"), coord["3"], krrgjsh) try: arcpy.CreateCustomGeoTransformation_management( name, gauss, utm, utm_2_gauss(-1)) arcpy.CreateCustomGeoTransformation_management( name2, utm, krrgjsh, utm_2_krrgjsh(-1)) except: print("Transformimi ekziston") arcpy.env.workspace = workingDir + "\\tempFolder\\test.gdb\\" + coord[ "2"] lyr = arcpy.ListFeatureClasses() for i in lyr: if i not in [ "Annotation", "MultiPatch", "Point", "Polygon", "Polyline" ]: continue arcpy.Project_management( i, os.path.join(workingDir, "tempFolder\\test.gdb", coord["1"], i + "_" + coord["1"]), utm, name, gauss, "NO_PRESERVE_SHAPE", None, "NO_VERTICAL") arcpy.Project_management( os.path.join(workingDir, "tempFolder\\test.gdb", coord["1"], i + "_" + coord["1"]), os.path.join(workingDir, "tempFolder\\test.gdb", coord["3"], i + "_" + coord["3"]), krrgjsh, name2, utm, "NO_PRESERVE_SHAPE", None, "NO_VERTICAL") for j in range(3): if j == 1: continue arcpy.env.workspace = workingDir + "\\tempFolder\\test.gdb\\" + coord[ str(j + 1)] lyr = arcpy.ListFeatureClasses() CADlayers = "" for i in lyr: CADlayers = CADlayers + arcpy.env.workspace + "\\" + i + ";" arcpy.ExportCAD_conversion( CADlayers, "DWG_R2013", os.path.join(workingDir, dwgName[:-4] + "_" + coord[str(j + 1)] + ".dwg"), "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")
def exportSurveyTopographyDXF(self, outFolder): """exports dxf file containing Topographic Survey Points, Lines and Survey Extent """ from os import path outfile = path.join(outFolder, "SurveyTopography") + ".dxf" memTopoPoints = "in_memory//Topo_Points" memEOW = "in_memory//EdgeofWater_Points" memBreaklines = "in_memory//Breaklines" memSurveyExtent = "in_memory//Survey_Extent" memPoints = "in_memory//AllPoints" # memLines = "in_memory//AllLines" memControlPoints = "in_memory//ControlPoints" listmemFCs = [memTopoPoints, memEOW, memBreaklines, memSurveyExtent] listmemAnnotation = [memPoints, memControlPoints] for fc in listmemFCs + listmemAnnotation: if arcpy.Exists(fc): arcpy.Delete_management(fc) arcpy.CopyFeatures_management(self.Topo_Points.filename, memTopoPoints) arcpy.CopyFeatures_management(self.EdgeOfWater_Points.filename, memEOW) arcpy.CopyFeatures_management(self.Breaklines.filename, memBreaklines) arcpy.CopyFeatures_management(self.SurveyExtent.filename, memSurveyExtent) arcpy.CopyFeatures_management(self.Control_Points.filename, memControlPoints) arcpy.CopyFeatures_management(self.Topo_Points.filename, memPoints) arcpy.ExportCAD_conversion([memBreaklines, memSurveyExtent, memPoints], "DXF_R2010", outfile) outCSV = path.join(outFolder, "SurveyTopographyPoints") + ".csv" exportAsCSV(memPoints, outCSV) outControlCSV = path.join(outFolder, "ControlNetworkPoints") + ".csv" exportAsCSV(memControlPoints, outControlCSV) return outfile
def main(): extents_file = arcpy.GetParameterAsText(0) cross_sections = arcpy.GetParameterAsText(1) XS_ID_field = arcpy.GetParameterAsText(2) round_stationing = arcpy.GetParameterAsText(3) round_digits = arcpy.GetParameterAsText(4) geo_file = arcpy.GetParameterAsText(5) outfilename = arcpy.GetParameterAsText(6) convert_to_CAD = arcpy.GetParameterAsText(7) arcpy.AddMessage('geofile: "' + geo_file + '"') if geo_file == '': arcpy.AddMessage( 'No HEC-RAS geometry file was supplied, not correcting skew and offset' ) if round_stationing == 'true': round_stationing = True else: round_stationing = False if round_digits != '': round_digits = int(round_digits) elif round_stationing: round_digits = 0 arcpy.AddWarning('Rounding digits left blank, defaulting to 0') arcpy.AddMessage('Creating: ' + outfilename) create_WS_extents(extents_file, cross_sections, XS_ID_field, round_stationing, round_digits, geo_file, outfilename) # Convert points to CAD if convert_to_CAD == 'true': arcpy.AddMessage('Exporting to CAD') arcpy.ExportCAD_conversion(outfilename, 'DWG_R2010', outfilename[:-3] + 'dwg')
arcpy.AddMessage( "*******************************************************************************" ) arcpy.AddMessage("") # Process: Calculate Field (2)... arcpy.CalculateField_management(projectedOutputLines, "Width", "[Shape_Length]", "VB", "") arcpy.AddMessage("Export to CAD") arcpy.AddMessage( "*******************************************************************************" ) arcpy.AddMessage("") # Process: Export to CAD... arcpy.ExportCAD_conversion( "Y:\\Projekte\\Geodaten\\Hoehen\\DTM_DOM_AWG\\Scratch\\Scratch.gdb\\ContSmoo_lv95;Y:\\Projekte\\Geodaten\\Hoehen\\DTM_DOM_AWG\\Scratch\\Scratch.gdb\\Points_lv95", "DXF_R14", OutputDXF, "Use_Filenames_in_Tables", "Overwrite_Existing_Files", "") arcpy.AddMessage("Loeschen der Zwischenresultate") arcpy.AddMessage( "*******************************************************************************" ) arcpy.AddMessage("") arcpy.Delete_management(ScratchRaster1) arcpy.Delete_management(cont_orig1) arcpy.Delete_management(OutputSmoothLine) arcpy.Delete_management(OutputEndPoints) arcpy.Delete_management(OutputMidPoints) arcpy.Delete_management(projectedOutputLines) arcpy.Delete_management(projectedOutputPoints)
def execute(self, parameters, messages): """The source code of the tool.""" arcpy.AddMessage("default.gdb_path: %s" % arcpy.env.workspace) arcpy.ImportToolbox(os.path.join(os.path.dirname(__file__), "URB.pyt")) arcpy.gp.toolbox = os.path.join(os.path.dirname(__file__), "URB.pyt") extent = parameters[0].value srs = parameters[1].value arcpy.AddMessage("control: %s %s" % (extent, srs)) ext_poly = ext2poly(extent, arcpy.SpatialReference(3003)) sel_fc = create_fc(ws="scratch") ext_fc_cursor = arcpy.da.InsertCursor(sel_fc, ("SHAPE@")) ext_fc_cursor.insertRow([ext_poly]) del ext_fc_cursor sel_lyr = arcpy.mapping.Layer(sel_fc) arcpy.AddMessage("sel_lyr: %s" % str(sel_lyr)) check_layer_list = [ [ r"Connessioni database\VISIO_R_GDBT.sde\SIT.DBTOPOGRAFICO\SIT.UN_VOL", "UN_VOL_AV", 0 ], [ r"Connessioni database\VISIO_R_GDBT.sde\SIT.DBTOPOGRAFICO\SIT.AATT", "", 1 ], [ r"Connessioni database\VISIO_R_GDBT.sde\SIT.DBTOPOGRAFICO\SIT.MN_EDI_NOVOL", "", 2 ], [ r"Connessioni database\VISIO_R_GDBT.sde\SIT.DBTOPOGRAFICO\SIT.MN_UVOL", "MN_UVO_ALT", 3 ], [ r"Connessioni database\VISIO_R_GDBT.sde\SIT.DBTOPOGRAFICO\SIT.AR_VRD", "", 4 ], #[r"Connessioni database\VISIO_R_GDBT.sde\SIT.DBTOPOGRAFICO\SIT.AR_MARC", "", 5], #[r"Connessioni database\VISIO_R_GDBT.sde\SIT.DBTOPOGRAFICO\SIT.AC_VEI", "", 6], [ r"Connessioni database\VISIO_R_GDBT.sde\SIT.DBTOPOGRAFICO\SIT.CL_AGR", "", 7 ], [ r"Connessioni database\VISIO_R_GDBT.sde\SIT.DBTOPOGRAFICO\SIT.A_PED", "", 8 ], [ r"Connessioni database\VISIO_R_GDBT.sde\SIT.DBTOPOGRAFICO\SIT.PS_INC", "", 9 ], ] sel_fc = get_jobfile("memory") sel_fc_fields = ( ("Layer", "TEXT", None, None, 10, "", "NULLABLE", "NON_REQUIRED"), ("Color", "SHORT", None, None, None, "", "NULLABLE", "NON_REQUIRED"), ("TxtValue", "TEXT", None, None, 10, "", "NULLABLE", "NON_REQUIRED"), ) intersectOutput_clean = create_fc("memory", fields=sel_fc_fields) sel_note = get_jobfile("memory") sel_note_fields = ( ("Layer", "TEXT", None, None, 50, "", "NULLABLE", "NON_REQUIRED"), ("Color", "SHORT", None, None, None, "", "NULLABLE", "NON_REQUIRED"), ("TxtValue", "TEXT", None, None, 255, "", "NULLABLE", "NON_REQUIRED"), ("CADType", "TEXT", None, None, 50, "", "NULLABLE", "NON_REQUIRED"), ) intersectOutput_note = create_fc("memory", fields=sel_note_fields, geom_type="POINT") cursor_note = arcpy.da.InsertCursor( intersectOutput_note, ("Layer", "Color", "TxtValue", "CADType", "SHAPE@")) for check_layer_def in check_layer_list: check_layer = check_layer_def[0] arcpy.AddMessage("check_layer: %s" % check_layer) desc = arcpy.Describe(check_layer) inFeatures = [check_layer, sel_lyr] intersectOutput = get_jobfile("memory") clusterTolerance = 0 arcpy.Intersect_analysis(inFeatures, intersectOutput, "", clusterTolerance, "input") if check_layer_def[1]: field_def = ("Layer", "Color", "TxtValue", "SHAPE@") check_def = [check_layer_def[1], "SHAPE@"] else: field_def = ("Layer", "Color", "SHAPE@") check_def = ["SHAPE@"] cursor_clean = arcpy.da.InsertCursor(intersectOutput_clean, field_def) with arcpy.da.SearchCursor(intersectOutput, check_def) as cursor: for row in cursor: if check_layer_def[1]: row_def = [ desc.name.replace("SIT.", ""), check_layer_def[2], str(row[0]), cursor[1] ] note_def = row_def[:-1] + [ "TEXT", arcpy.PointGeometry(cursor[1].centroid) ] cursor_note.insertRow(note_def) else: row_def = [ desc.name.replace("SIT.", ""), check_layer_def[2], cursor[0] ] cursor_clean.insertRow(row_def) del cursor_clean del cursor_note extraction_json_filepath = get_jobfile("output", "json") arcpy.FeaturesToJSON_conversion(intersectOutput_clean, extraction_json_filepath, format_json=True, geoJSON=True) arcpy.AddMessage(extraction_json_filepath) parameters[2].value = extraction_json_filepath extraction_dxf_filepath = get_jobfile("output", "dxf") arcpy.ExportCAD_conversion( [intersectOutput_clean, intersectOutput_note], "DXF_R2004", extraction_dxf_filepath, "USE_FILENAMES_IN_TABLES", "OVERWRITE_EXISTING_FILES", "") parameters[3].value = extraction_dxf_filepath lyr = arcpy.mapping.Layer(intersectOutput_clean) parameters[4].value = intersectOutput_clean
input_layers = arcpy.GetParameterAsText(0) output_folder = arcpy.GetParameterAsText(1) # split the input string to list (the input layers enter as string) input_layers = input_layers.split(";") print(arcpy.AddMessage(input_layers[0])) print(arcpy.AddMessage(type(input_layers[0]))) # set the counter for giving different color for each output cad layer counter = 0 # loop throw the list of input layers and export each one try: for i in input_layers: counter += 1 in_memory = r"in_memory\\" arcpy.CopyFeatures_management(i, in_memory + i) arcpy.AddField_management(in_memory + i, 'Layer', 'text') arcpy.CalculateField_management(in_memory + i, 'Layer', i) arcpy.AddField_management(in_memory + i, 'LyrColor', 'short') arcpy.CalculateField_management(in_memory + i, 'LyrColor', counter) output_type = "DWG_R2000" output_file = output_folder + "\\" + i + '.dwg' print(arcpy.AddMessage(output_file)) arcpy.ExportCAD_conversion(in_memory + i, output_type, output_file) arcpy.Delete_management(r"in_memory") print(arcpy.AddMessage("all layers was expoerted!")) except arcpy.ExecuteError: print(arcpy.AddMessage("All layers must not be in group!!!")) raise
clause = "NUMSYMBOL <12" arcpy.Select_analysis("AUXILIAR\\CONSTRU_2.shp", "AUXILIAR\\CONSTRU_3.shp", clause) arcpy.Select_analysis("AUXILIAR\\CONSTRU_3.shp", "AUXILIAR\\ALTAS_.shp", "ALTAS<>0") arcpy.Dissolve_management("AUXILIAR\\ALTAS_.shp", "ALTAS.shp", "REFCAT", [["AREA", "SUM"]], "SINGLE_PART") #Aqui se crea una nueva capa plantas bajas BAIXOS (disuelta por REFerenciaCATastral) arcpy.Erase_analysis("AUXILIAR\\CONSTRU_3.shp", "DOMPUB.shp", "AUXILIAR\\CONSTRU_4.shp") arcpy.Select_analysis("AUXILIAR\\CONSTRU_4.shp", "AUXILIAR\\BAIXOS_.shp", "BAIXA<>0") arcpy.Dissolve_management("AUXILIAR\\BAIXOS_.shp", "BAIXOS.shp", "REFCAT", [["AREA", "SUM"]], "SINGLE_PART") #Aqui se exportan las 5 capas a CAD con los mismos nombres arcpy.ExportCAD_conversion("ALTAS.shp", "DWG_R2010", "ALTAS.dwg", "USE_FILENAMES_IN_TABLES") arcpy.ExportCAD_conversion("BAIXOS.shp", "DWG_R2010", "BAIXOS.dwg", "USE_FILENAMES_IN_TABLES") arcpy.ExportCAD_conversion("CONSTRU.shp", "DWG_R2010", "CONSTRU.dwg", "USE_FILENAMES_IN_TABLES") arcpy.ExportCAD_conversion("DOMPUB.shp", "DWG_R2010", "DOMPUB.dwg", "USE_FILENAMES_IN_TABLES") arcpy.ExportCAD_conversion("PARCELA.shp", "DWG_R2010", "PARCELA.dwg", "USE_FILENAMES_IN_TABLES") #Por ultimo se borran las capas auxiliares utilizadas shutil.rmtree(auxiliar)
"in_memory\\outClipFeatureClass") #need to copy from in_memory to folder to the desktop folder FCmem = arcpy.CopyFeatures_management(memClip, outClipFeatureClass) ### keep log of number of feature classes that are empty... if arcpy.management.GetCount(FCmem)[0] == "0": emptFC += 1 arcpy.Delete_management(memClip) #counter used to determine if loop is completely finished and ready to move on on to CAD conversion if fileCount == 0: arcpy.Delete_management(memClipFeature) dwgShapefiles = arcpy.ListFeatureClasses() outCAD = arcpy.ExportCAD_conversion(dwgShapefiles, "DWG_R2013", "{0}.dwg".format(x), "IGNORE_FILENAMES_IN_TABLES", "APPEND_TO_EXISTING_FILES", "") #### ZIPFILE BELOW #### shutil.make_archive(segFold, 'zip', folderPath) # End process... endtime = datetime.datetime.now() # Total feature classes in clip that are empty f.write('Total number of empty input feature classes: ' + str(emptFC) + '\n') f.write('\n') # Process Completed... f.write('CAD extractions completed successfully in ' + str(endtime - starttime) + '\n') f.write("--------------------" + "\n") f.write("--------------------" + "\n")
# coding=gbk import arcpy import os dir = 'D:\\project13\\output\\³ׯ401\\'.decode('gbk') features = [] output_type = "DWG_R2010" output_file = dir+"/cad.dwg" flist = os.listdir(dir) for i in flist: if i.endswith('shp'): features.append(dir+''+i[:-4]) for i in features: print i feature = 'D:\\project13\\output\\³ׯ401\\bianyaqi.shp' arcpy.ExportCAD_conversion(feature,output_type,output_file,"USE_FILENAMES_IN_TABLES", "OVERWRITE_EXISTING_FILES", "")
arcpy.AlterField_management(fc, "ATT1", "COD") arcpy.CalculateField_management(fc, "Layer", "'Point topo - ' + !CODE_DESCR!", "PYTHON_9.3") else: # fc=="Topo_Stations" # On nomme ici le bloc "station" inséré dans le gabarit DAO arcpy.CalculateField_management(fc, "RefName", "'TopoStation'", "PYTHON_9.3") # On définit les attributs du bloc "station topo", ici MAT et COD arcpy.AlterField_management(fc, "Matricule", "MAT") arcpy.AlterField_management(fc, "Observation", "COD") arcpy.CalculateField_management(fc, "Layer", "'Station topo'", "PYTHON_9.3") elif fc == "FUS_Bord_Pln": arcpy.CalculateField_management(fc, "Layer", "!LEGENDE!", "PYTHON_9.3") else: arcpy.CalculateField_management(fc, "Layer", "!CODE_DESCR!", "PYTHON_9.3") print u"Attributs DAO pour " + fc + u" ajoutés." print u"Champs DAO ajoutés aux classes d'entités et calculés.\n" # Export DXF/DWG # Attention c'est le gabarit qui définit le format de fichier (DWG/DXF,version) # mais sans modifier l'extension print u"Génération du fihier DAO..." arcpy.ExportCAD_conversion(fcList, "DWG_R2007", output_dao_path,"Ignore_Filenames_in_Tables","Append_To_Existing_Files", gabarit_dao_path) later = datetime.datetime.now() elapsed = later - now print(u'Le fichier DAO a été généré en {} secondes.').format(elapsed) # except Exception as err: # arcpy.AddError(err) # print err
workspace=r"C:\Users\hanye\Desktop\kml"): arcpy.env.overwriteOutput = True kmls = arcpy.ListFiles("*.kml") for file in kmls: arcpy.conversion.KMLToLayer( r"C:\Users\hanye\Desktop\kml\{}".format(file), r"C:\Users\hanye\Desktop\kml\geodb", "{}".format(file[0:8]), "NO_GROUNDOVERLAY") arcpy.env.workspace = (r"C:\Users\hanye\Desktop\kml\geodb") workspaces = arcpy.ListWorkspaces("*", "FileGDB") for ws in workspaces: gdb = arcpy.Compact_management(ws) arcpy.env.workspace = ws fds = arcpy.ListDatasets() listFC = [] for fd in fds: arcpy.env.workspace = os.path.join(ws, fd) fcs = arcpy.ListFeatureClasses() listFC += fcs for fc in listFC: arcpy.ExportCAD_conversion( fcs, "DWG version 2007", r"C:\Users\hanye\Desktop\kml\cad\{}.dwg".format(ws[-12:-4]), "USE_FILENAMES_IN_TABLES", "OVERWRITE_EXISTING_FILES") print("ALL DON GEOCODER")
newLayer = arcpy.KMLToLayer_conversion(inKML, outLocation) fgdbs = arcpy.ListWorkspaces(os.path.basename(inKML)[:-4] + '*', 'FileGDB') arcpy.AddMessage("Workspaces: " + str(fgdbs)) if os.path.exists( os.path.join(outLocation, os.path.basename(inKML)[:-4] + ".dxf")): os.remove(os.path.join(outLocation, os.path.basename(inKML)[:-4] + ".dxf")) try: os.remove( os.path.join(outLocation, os.path.basename(inKML)[:-4] + ".dxf.xml")) except: pass for fgdb in fgdbs: arcpy.env.workspace = fgdb for dataset in arcpy.ListDatasets(): featureClasses = arcpy.ListFeatureClasses('', '', dataset) arcpy.AddMessage(str(featureClasses)) for fc in featureClasses: arcpy.ExportCAD_conversion( fc, 'DXF_R2013', os.path.join(outLocation, os.path.basename(inKML)[:-4] + ".dxf"), 'IGNORE_FILENAMES_IN_TABLES', 'APPEND_TO_EXISTING_FILES') #TO DO: Make these things work. ArcGIS locks up everything it touches, like some kind of masochistic judge #arcpy.Delete_management(fgdb) #del featureClasses, fgdbs, fgdb, newLayer, fc
def fc2dwg(dwgname): in_features = arcpy.ListFeatureClasses() output_type = "DWG_R2007" output_file = 'F:/file/' + dwgname arcpy.ExportCAD_conversion(in_features, output_type, output_file)
def clipFeatures(params, job, convertFeaturesDuringClip=True): global haveDataInterop cleanUpFeatureLayer = False # get the path and a validated name for the output layerName, outputpath = make_output_path(False, job['layer'], job['name'], convertFeaturesDuringClip, params.input_feature_format, params.zip_folder_path, params.scratch_folder_path, outputDataFolderName=params.output_folder_name) arcpy.AddMessage("Starting layer: %s where: %s" % (job['layer'], job['where'])) feature_layer = layerName cleanUpFeatureLayer = True try: arcpy.MakeFeatureLayer_management(job['layer'], feature_layer) arcpy.SelectLayerByAttribute_management(feature_layer, "NEW_SELECTION", job['where']) #introspect_featureset(feature_layer, job['where']) count = int(arcpy.GetCount_management(feature_layer).getOutput(0)) except: arcpy.AddWarning("Select Attributes Error :: Layer=%s; Clause=%s" % (feature_layer, job['where'])) arcpy.AddWarning(arcpy.GetMessages(2)) raise return if count == 0: arcpy.AddWarning("Where clause yielded no records :: Layer=%s; Clause=%s" % (feature_layer, job['where'])) return try: if params.output_projection and params.output_projection in VALID_PROJECTION_ALIASES.keys(): arcpy.AddMessage('Ready to project: feature_layer=%s; outputpath=%s' % (feature_layer, outputpath)) out_coordinate_system = os.path.join(PROJECTIONS_FOLDER, VALID_PROJECTION_ALIASES[params.output_projection]) arcpy.Project_management(feature_layer, outputpath, out_coordinate_system) else: arcpy.AddMessage('Ready to copy: feature_layer=%s; outputpath=%s' % (feature_layer, outputpath)) arcpy.CopyFeatures_management(feature_layer, outputpath) # if format needs data interop, convert with data interop if not convertFeaturesDuringClip: # get path to zip outputinzip = os.path.join(zipFolderPath, layerName + featureFormat[2]) if featureFormat[2].lower() in [".dxf", ".dwg", ".dgn"]: #Message "..using export to cad.." arcpy.AddWarning(get_ID_message(86139)) arcpy.ExportCAD_conversion(outputpath, featureFormat[1], outputinzip) else: if not haveDataInterop: raise LicenseError diFormatString = "%s,%s" % (featureFormat[1], outputinzip) # run quick export arcpy.quickexport_interop(outputpath, diFormatString) except LicenseError: #Message " failed to export to %s. The requested formats require the Data Interoperability extension. This extension is currently unavailable." arcpy.AddWarning(get_ID_message(86140) % featureFormat[1]) pass except: raise finally: if cleanUpFeatureLayer and arcpy.Exists(feature_layer): arcpy.Delete_management(feature_layer)
z_coord = "Z" out_Layer = "tor_1_points" tor1_shp = r"E:\GIS Programming\Tory_Stacja_Korsze\tor_1_point.shp" # Make the XY event layer... arcpy.MakeXYEventLayer_management(in_Table, x_coord, y_coord, out_Layer, pjr) # Save to a layer file arcpy.MakeFeatureLayer_management(out_Layer, tor1_shp) # Creating lines from points tor1_line_shp = r"E:\GIS Programming\Tory_Stacja_Korsze\tor1_line.shp" arcpy.PointsToLine_management(tor1_shp, tor1_line_shp) # Save to a layer file (tor_line_shp) save_line = r"E:\GIS Programming\Tory_Stacja_Korsze\tor_1_line.shp" arcpy.MakeFeatureLayer_management(tor1_line_shp, save_line) # Deleting temporary layers arcpy.Delete_management("tor_1_points") arcpy.Delete_management("tor1_line") # Exporting features to dwg arcpy.ExportCAD_conversion(tor1_line_shp, "DXF_R2010", path_dxf) #'E:/GIS Programming/Tory_Stacja_Korsze/DWG/tor1.dwg'