def read_gpx_file(self, context): scene = context.scene # a list of track segments (trkseg) segments = [] minLat = 90 maxLat = -90 minLon = 180 maxLon = -180 gpx = etree.parse(self.filepath).getroot() for e1 in gpx: # e stands for element # Each tag may have the form {http://www.topografix.com/GPX/1/1}tag # That's whay we skip curly brackets if e1.tag[e1.tag.find("}")+1:] == "trk": for e2 in e1: if e2.tag[e2.tag.find("}")+1:] == "trkseg": segment = [] for e3 in e2: if e3.tag[e3.tag.find("}")+1:] == "trkpt": lat = float(e3.attrib["lat"]) lon = float(e3.attrib["lon"]) # calculate track extent if lat<minLat: minLat = lat elif lat>maxLat: maxLat = lat if lon<minLon: minLon = lon elif lon>maxLon: maxLon = lon # check if <trkpt> has <ele> ele = None for e4 in e3: if e4.tag[e4.tag.find("}")+1:] == "ele": ele = e4 break point = (lat, lon, float(ele.text)) if self.useElevation and ele is not None else (lat, lon) segment.append(point) segments.append(segment) if "latitude" in scene and "longitude" in scene and not self.ignoreGeoreferencing: lat = scene["latitude"] lon = scene["longitude"] else: lat = (minLat + maxLat)/2 lon = (minLon + maxLon)/2 scene["latitude"] = lat scene["longitude"] = lon projection = TransverseMercator(lat=lat, lon=lon) # create vertices and edges for the track segments for segment in segments: prevVertex = None for point in segment: v = projection.fromGeographic(point[0], point[1]) v = self.bm.verts.new((v[0], v[1], point[2] if self.useElevation and len(point)==3 else 0)) if prevVertex: self.bm.edges.new([prevVertex, v]) prevVertex = v
def read_gpx_file(self, context): scene = context.scene # a list of track segments (trkseg) segments = [] minLat = 90 maxLat = -90 minLon = 180 maxLon = -180 gpx = etree.parse(self.filepath).getroot() for e1 in gpx: # e stands for element # Each tag may have the form {http://www.topografix.com/GPX/1/1}tag # That's whay we skip curly brackets if e1.tag[e1.tag.find("}")+1:] == "trk": for e2 in e1: if e2.tag[e2.tag.find("}")+1:] == "trkseg": segment = [] for e3 in e2: if e3.tag[e3.tag.find("}")+1:] == "trkpt": lat = float(e3.attrib["lat"]) lon = float(e3.attrib["lon"]) # calculate track extent if lat<minLat: minLat = lat elif lat>maxLat: maxLat = lat if lon<minLon: minLon = lon elif lon>maxLon: maxLon = lon # check if <trkpt> has <ele> ele = None for e4 in e3: if e4.tag[e4.tag.find("}")+1:] == "ele": ele = e4 break point = (lat, lon, float(ele.text)) if self.useElevation and ele is not None else (lat, lon) segment.append(point) segments.append(segment) if "lat" in scene and "lon" in scene and not self.ignoreGeoreferencing: lat = scene["lat"] lon = scene["lon"] else: lat = (minLat + maxLat)/2 lon = (minLon + maxLon)/2 scene["lat"] = lat scene["lon"] = lon projection = TransverseMercator(lat=lat, lon=lon) # create vertices and edges for the track segments for segment in segments: prevVertex = None for point in segment: v = projection.fromGeographic(point[0], point[1]) v = self.bm.verts.new((v[0], v[1], point[2] if self.useElevation and len(point)==3 else 0)) if prevVertex: self.bm.edges.new([prevVertex, v]) prevVertex = v
def read_osm_file(self, context): scene = context.scene osm = OsmParser( self.filepath, # possible values for wayHandlers and nodeHandlers list elements: # 1) a string name for the module containing classes (all classes from the modules will be used as handlers) # 2) a python variable representing the module containing classes (all classes from the modules will be used as handlers) # 3) a python variable representing the class wayHandlers=[buildings ] #[handlers.buildings] #[handlers] #["handlers"] ) if "latitude" in scene and "longitude" in scene and not self.ignoreGeoreferencing: lat = scene["latitude"] lon = scene["longitude"] else: lat = (osm.minLat + osm.maxLat) / 2 lon = (osm.minLon + osm.maxLon) / 2 scene["latitude"] = lat scene["longitude"] = lon osm.parse( projection=TransverseMercator(lat=lat, lon=lon), thickness=self.thickness, bm=self. bm # if present, indicates the we need to create as single mesh )
def execute(self, context): scene = context.scene refObjectData = _.refObjectData refObject = refObjectData[0] # calculationg new position of the reference object center p = refObject.matrix_world * (-refObjectData[1]) projection = TransverseMercator(lat=scene["latitude"], lon=scene["longitude"]) (lat, lon) = projection.toGeographic(p[0], p[1]) scene["longitude"] = lon scene["latitude"] = lat scene["heading"] = (refObject.rotation_euler[2]-refObjectData[2])*180/math.pi # restoring original objects location and orientation bpy.ops.transform.rotate(value=-(refObject.rotation_euler[2]-refObjectData[2]), axis=(0,0,1)) bpy.ops.transform.translate(value=-(refObject.location-refObjectData[1])) # cleaning up _.refObjectData = None return {"FINISHED"}
def execute(self, context): wm = context.window_manager scene = context.scene o = scene.objects.active # calculationg the new position of the active object center v = -Vector((wm["_x"], wm["_y"], o.location.z)) p = o.matrix_world * v projection = TransverseMercator(lat=scene["latitude"], lon=scene["longitude"]) (lat, lon) = projection.toGeographic(p[0], p[1]) scene["longitude"] = lon scene["latitude"] = lat scene["heading"] = (o.rotation_euler[2]-wm["_h"])*180/math.pi # restoring original objects location and orientation bpy.ops.transform.rotate(value=-(o.rotation_euler[2]-wm["_h"]), axis=(0,0,1)) bpy.ops.transform.translate(value=-(o.location+v)) # cleaning up del wm["_x"], wm["_y"], wm["_h"] return {"FINISHED"}
def execute(self, context): wm = context.window_manager scene = context.scene o = scene.objects.active # calculationg the new position of the active object center v = -Vector((wm["_x"], wm["_y"], o.location.z)) p = o.matrix_world * v projection = TransverseMercator(lat=scene["latitude"], lon=scene["longitude"]) (lat, lon) = projection.toGeographic(p[0], p[1]) scene["longitude"] = lon scene["latitude"] = lat scene["heading"] = (o.rotation_euler[2] - wm["_h"]) * 180 / math.pi # restoring original objects location and orientation bpy.ops.transform.rotate(value=-(o.rotation_euler[2] - wm["_h"]), axis=(0, 0, 1)) bpy.ops.transform.translate(value=-(o.location + v)) # cleaning up del wm["_x"], wm["_y"], wm["_h"] return {"FINISHED"}
def read_osm_file(self, context): scene = context.scene wayHandlers = [] if self.importBuildings: wayHandlers.append(Buildings) wayHandlers.append(BuildingParts) if self.importNaturals: wayHandlers.append(Naturals) if self.importHighways: wayHandlers.append(Highways) osm = OsmParser( self.filepath, # possible values for wayHandlers and nodeHandlers list elements: # 1) a string name for the module containing classes (all classes from the modules will be used as handlers) # 2) a python variable representing the module containing classes (all classes from the modules will be used as handlers) # 3) a python variable representing the class # Examples: # wayHandlers = [buildings, highways] # wayHandlers = [handlers.buildings] # wayHandlers = [handlers] # wayHandlers = ["handlers"] wayHandlers=wayHandlers) if "latitude" in scene and "longitude" in scene and not self.ignoreGeoreferencing: lat = scene["latitude"] lon = scene["longitude"] else: if osm.bounds and self.importHighways: # If the .osm file contains the bounds tag, # use its values as the extent of the imported area. # Highways may go far beyond the values of the bounds tag. # A user might get confused if higways are used in the calculation of the extent of the imported area. bounds = osm.bounds lat = (bounds["minLat"] + bounds["maxLat"]) / 2 lon = (bounds["minLon"] + bounds["maxLon"]) / 2 else: lat = (osm.minLat + osm.maxLat) / 2 lon = (osm.minLon + osm.maxLon) / 2 scene["latitude"] = lat scene["longitude"] = lon osm.parse( projection=TransverseMercator(lat=lat, lon=lon), defaultHeight=self.defaultHeight, levelHeight=self.levelHeight, bm=self. bm # if present, indicates the we need to create as single mesh )
def execute(self, context): scene = context.scene refObjectData = _.refObjectData refObject = refObjectData[0] # calculationg new position of the reference object center p = refObject.matrix_world * (-refObjectData[1]) projection = TransverseMercator(lat=scene["latitude"], lon=scene["longitude"]) (lat, lon) = projection.toGeographic(p[0], p[1]) scene["longitude"] = lon scene["latitude"] = lat scene["heading"] = (refObject.rotation_euler[2] - refObjectData[2]) * 180 / math.pi # restoring original objects location and orientation bpy.ops.transform.rotate( value=-(refObject.rotation_euler[2] - refObjectData[2]), axis=(0, 0, 1)) bpy.ops.transform.translate( value=-(refObject.location - refObjectData[1])) # cleaning up _.refObjectData = None return {"FINISHED"}
def execute(self, context): scene = context.scene projection = None if "latitude" in scene and "longitude" in scene and not self.ignoreGeoreferencing: projection = TransverseMercator(lat=scene["latitude"], lon=scene["longitude"]) if self.useSelectionAsExtent: bbox = getSelectionBoundingBox(context) if not bbox or bbox["xmin"] >= bbox["xmax"] or bbox[ "ymin"] >= bbox["ymax"]: self.report({ "ERROR" }, "No objects are selected or extent of the selected objects is incorrect" ) return {"FINISHED"} # convert bbox to geographical coordinates (minLat, minLon) = projection.toGeographic(bbox["xmin"], bbox["ymin"]) (maxLat, maxLon) = projection.toGeographic(bbox["xmax"], bbox["ymax"]) elif self.useSpecificExtent: minLat = self.minLat maxLat = self.maxLat minLon = self.minLon maxLon = self.maxLon else: # use extent of the self.filepath (a single .hgt file) srtmFileName = os.path.basename(self.filepath) if not srtmFileName: self.report({"ERROR"}, "A .hgt file with SRTM data wasn't specified") return {"FINISHED"} minLat = int(srtmFileName[1:3]) if srtmFileName[0] == "S": minLat = -minLat maxLat = minLat + 1 minLon = int(srtmFileName[4:7]) if srtmFileName[3] == "W": minLon = -minLon maxLon = minLon + 1 # remember if we have georeferencing _projection = projection if not projection: projection = TransverseMercator(lat=(minLat + maxLat) / 2, lon=(minLon + maxLon) / 2) srtm = Srtm( minLat=minLat, maxLat=maxLat, minLon=minLon, maxLon=maxLon, projection=projection, srtmDir=os.path.dirname( self.filepath), # directory for the .hgt files primitiveType=self.primitiveType) missingSrtmFiles = srtm.getMissingSrtmFiles() if missingSrtmFiles: for missingFile in missingSrtmFiles: self.report({"ERROR"}, "SRTM file %s is missing" % missingFile) return {"FINISHED"} verts = [] indices = [] srtm.build(verts, indices) # create a mesh object in Blender mesh = bpy.data.meshes.new("SRTM") mesh.from_pydata(verts, [], indices) mesh.update() obj = bpy.data.objects.new("SRTM", mesh) # set custom parameter "latitude" and "longitude" to the active scene if not _projection: scene["latitude"] = projection.lat scene["longitude"] = projection.lon bpy.context.scene.objects.link(obj) return {"FINISHED"}
def execute(self, context): scene = context.scene projection = None if "lat" in scene and "lon" in scene and not self.ignoreGeoreferencing: projection = TransverseMercator(lat=scene["lat"], lon=scene["lon"]) if self.useSelectionAsExtent: bbox = getSelectionBoundingBox(context) if not bbox or bbox["xmin"]>=bbox["xmax"] or bbox["ymin"]>=bbox["ymax"]: self.report({"ERROR"}, "No objects are selected or extent of the selected objects is incorrect") return {"FINISHED"} # convert bbox to geographical coordinates (minLat, minLon) = projection.toGeographic(bbox["xmin"], bbox["ymin"]) (maxLat, maxLon) = projection.toGeographic(bbox["xmax"], bbox["ymax"]) elif self.useSpecificExtent: minLat = self.minLat maxLat = self.maxLat minLon = self.minLon maxLon = self.maxLon else: # use extent of the self.filepath (a single .hgt file) srtmFileName = os.path.basename(self.filepath) if not srtmFileName: self.report({"ERROR"}, "A .hgt file with terrain data wasn't specified") return {"FINISHED"} minLat = int(srtmFileName[1:3]) if srtmFileName[0]=="S": minLat = -minLat maxLat = minLat + 1 minLon = int(srtmFileName[4:7]) if srtmFileName[3]=="W": minLon = -minLon maxLon = minLon + 1 # remember if we have georeferencing _projection = projection if not projection: projection = TransverseMercator(lat=(minLat+maxLat)/2, lon=(minLon+maxLon)/2) srtm = Srtm( minLat=minLat, maxLat=maxLat, minLon=minLon, maxLon=maxLon, projection=projection, srtmDir=os.path.dirname(self.filepath), # directory for the .hgt files primitiveType = self.primitiveType, size = 3600//int(self.resolution) ) missingSrtmFiles = srtm.getMissingSrtmFiles() # download missing SRTM files for missingPath in missingSrtmFiles: missingFile = os.path.basename(missingPath) url = "http://s3.amazonaws.com/elevation-tiles-prod/skadi/%s/%s" % (missingFile[:3], missingFile) print("Downloading the file from %s..." % url) try: request.urlretrieve(url, missingPath) except Exception as e: self.report({'ERROR'}, str(e)) return {'FINISHED'} print("Saving the file to %s... Done." % missingPath) verts = [] indices = [] srtm.build(verts, indices) # create a mesh object in Blender mesh = bpy.data.meshes.new("Terrain") mesh.from_pydata(verts, [], indices) mesh.update() obj = bpy.data.objects.new("Terrain", mesh) # set custom parameter "lat" and "lon" to the active scene if not _projection: scene["lat"] = projection.lat scene["lon"] = projection.lon bpy.context.scene.objects.link(obj) return {"FINISHED"}
def execute(self, context): scene = context.scene projection = None if "latitude" in scene and "longitude" in scene and not self.ignoreGeoreferencing: projection = TransverseMercator(lat=scene["latitude"], lon=scene["longitude"]) if self.useSelectionAsExtent: bbox = getSelectionBoundingBox(context) if not bbox or bbox["xmin"]>=bbox["xmax"] or bbox["ymin"]>=bbox["ymax"]: self.report({"ERROR"}, "No objects are selected or extent of the selected objects is incorrect") return {"FINISHED"} # convert bbox to geographical coordinates (minLat, minLon) = projection.toGeographic(bbox["xmin"], bbox["ymin"]) (maxLat, maxLon) = projection.toGeographic(bbox["xmax"], bbox["ymax"]) elif self.useSpecificExtent: minLat = self.minLat maxLat = self.maxLat minLon = self.minLon maxLon = self.maxLon else: # use extent of the self.filepath (a single .hgt file) srtmFileName = os.path.basename(self.filepath) if not srtmFileName: self.report({"ERROR"}, "A .hgt file with SRTM data wasn't specified") return {"FINISHED"} prefixLat = srtmFileName[0] minLat = int(srtmFileName[1:3]) maxLat = minLat + 1 prefixLon = srtmFileName[3] minLon = int(srtmFileName[4:7]) maxLon = minLon + 1 # remember if we have georeferencing _projection = projection if not projection: projection = TransverseMercator(lat=(minLat+maxLat)/2, lon=(minLon+maxLon)/2) srtm = Srtm( minLat=minLat, maxLat=maxLat, minLon=minLon, maxLon=maxLon, projection=projection, srtmDir=os.path.dirname(self.filepath), # directory for the .hgt files primitiveType = self.primitiveType ) missingSrtmFiles = srtm.getMissingSrtmFiles() if missingSrtmFiles: for missingFile in missingSrtmFiles: self.report({"ERROR"}, "SRTM file %s is missing" % missingFile) return {"FINISHED"} verts = [] indices = [] srtm.build(verts, indices) # create a mesh object in Blender mesh = bpy.data.meshes.new("SRTM") mesh.from_pydata(verts, [], indices) mesh.update() obj = bpy.data.objects.new("SRTM", mesh) # set custom parameter "latitude" and "longitude" to the active scene if not _projection: scene["latitude"] = projection.lat scene["longitude"] = projection.lon bpy.context.scene.objects.link(obj) return {"FINISHED"}