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"}
예제 #3
0
    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"}
예제 #4
0
    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"}
예제 #6
0
 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"}
예제 #7
0
	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"}