def CADtoGDB(CADpath, GDBpath):
    arcpy.ClearWorkspaceCache_management()
    reference_scale = "1000"
    CAD_name = CADpath.split("/")[-1][:-4]
    print "Converting", CAD_name, "FROM", CADpath, "to be PLACED in ", out_gdb_path
    try:
        ar.CADToGeodatabase_conversion(CADpath, GDBpath, CAD_name,
                                       reference_scale)
    except:
        print "File may already be there.  Attempting to replace/update"
        arcpy.Delete_management(
            str(GDBpath) + "/" + str(CAD_name), "DEFeatureDataset")
        ar.CADToGeodatabase_conversion(CADpath, GDBpath, CAD_name,
                                       reference_scale)
示例#2
0
 def execute(self, parameters, messages):
     """The source code of the tool."""
     source = parameters[0].valueAsText
     referenceScale = parameters[1].value
     coordinateSystem = parameters[2].valueAsText
     import os
     # make a file gdb in source
     arcpy.CreateFileGDB_management(source, "CAD2FGDB.gdb")
     for root, dirs, files in os.walk(source):
         for fname in files:
             if fname[-3:] in ["dgn", "dwg"]:
                 for i in ["-", " ", "(",
                           ")"]:  # check for illegal characters in name
                     if i in fname:
                         oldName = root + "\\" + fname
                         newName = root + "\\" + fname.replace(i, "_")
                         os.rename(
                             oldName, newName
                         )  # rename file if illegal characters found
                         cadFile = newName
                         outName = newName[:-4]
                     else:
                         cadFile = root + "\\" + fname
                         outName = fname[:-4]
                 outGDB = source + "\\CAD2FGDB.gdb"
                 arcpy.CADToGeodatabase_conversion(cadFile, outGDB, outName,
                                                   referenceScale,
                                                   coordinateSystem)
 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", "")
    if counter > 0:
        f_data[en].extend([f_data[en - 1][-1] + list(
            [calculateDistance(points[2], points[3], f_data[en - 1][2], f_data[en - 1][3], ProjectionFile)][0])[1]])
    else:
        f_data[en].extend([0])
print t.incremental_runtime()

ConvertedCADName = u'TempCad'
if not (arcpy.Exists(GeoDataBaseFolderLocation)):
    arcpy.CreateFileGDB_management(os.path.dirname(GeoDataBaseFolderLocation),
                                   os.path.basename(GeoDataBaseFolderLocation))
    print "A new filegeodabase has been created"
else:
    print "Geodatabase has Already Been Created"
print t.incremental_runtime()
arcpy.CADToGeodatabase_conversion(CADFileLocation, GeoDataBaseFolderLocation, ConvertedCADName, 1000)
print "CAD has been converted"
print t.incremental_runtime()
gdblocation = GeoDataBaseFolderLocation + "/" + ConvertedCADName
liste_of_groupings = list(set(
    [row[1] for row in arcpy.da.SearchCursor(gdblocation + "/Annotation", ["Layer", "TextString"]) if
     row[0].find(CrossSectionIdentifier) != -1]))
re_pattern = '(?=[0-9]{1,}\+).|(?<=[0-9]\+).+$'
p = re.compile(re_pattern)
a = []

for i in liste_of_groupings:
    m = p.findall(i)
    a.append([int(m[0]), float(m[1].replace('</UND>', ''))])
b = sorted(a, key=lambda l: (l[0], l[1]), reverse=False)
示例#5
0
文件: CAD.py 项目: JurajSt/postgis
import arcpy
import glob
import os
import ogr
from connectionData import pathCad, pathShp, typeCadFile, field
arcpy.env.overwriteOutput = True
gdb = pathCad + "/dgn.gdb"
arcpy.env.workspace = gdb
arcpy.CreateFileGDB_management(pathCad, "dgn.gdb")
reference_scale = "1500"
#globTxt = "r,"+ pathCad +"/*."+typeCadFile
for file in glob.glob(r"data/dgn_dxf/*.dgn"):
    outDS = arcpy.ValidateTableName(
        os.path.splitext(os.path.basename(file))[0])
    arcpy.CADToGeodatabase_conversion(file, gdb, outDS, reference_scale)

datasetList = arcpy.ListDatasets('*', 'Feature')
for dataset in datasetList:
    arcpy.env.workspace = dataset
    fcList = arcpy.ListFeatureClasses()
    for fc in fcList:
        #if fc == "Point" or fc == "Polyline" or fc == "Polygon":
        print fc
        inFeatures = fc
        outLocation = pathCad
        outFeatureClass = fc
        arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outLocation,
                                                    outFeatureClass)
示例#6
0
				arcpy.CADToGeodatabase_conversion(file, gdb, dgnName , "300")
				for FC in (gdb + "\\" + dgnName):
					if "Polyline" in FC:
						lines = os.path.abspath(FC)

'''

for fl in os.listdir(CADFolder):
    print "searching cad folder"
    print fl
    print os.path.splitext(os.path.basename(fl))[1]
    if os.path.splitext(os.path.basename(fl))[1] == ".dgn":
        print "found a dgn file"
        dgnName = "s" + str(os.path.splitext(os.path.basename(fl))[0])
        print dgnName
        arcpy.CADToGeodatabase_conversion((CADFolder + "\\" + fl), gdb,
                                          dgnName, "300")
        arcpy.env.workspace = gdb
        for fds in arcpy.ListDatasets('', 'feature'):
            if fds == dgnName:
                for fc in arcpy.ListFeatureClasses('', '', fds):
                    print "searching geodatabase for the new FC"
                    if "Polyline" in fc:
                        print "found a polyline file "
                        #lines = fc
                        endPoints = r"C:\Users\kevin.takala\Desktop\Arc_Proj\test\Endpoints.shp"
                        arcpy.FeatureVerticesToPoints_management(
                            fc, endPoints, "BOTH_ENDS")
                        #shapefile = fiona.open(endPoints)
                        with fiona.open(endPoints) as shapefile:
                            points = [
                                geometry.shape(point['geometry'])