コード例 #1
0
    def __init__(self, quadTreeId, image, transformDict):
        self.quadTreeId = quadTreeId
        self.image = image
        self.transform = transform.makeTransform(transformDict)

        corners = getImageCorners(self.image)
        self.mercatorCorners = [
            self.transform.forward(corner) for corner in corners
        ]

        if 0:
            # debug getProjectiveInverse
            print >> sys.stderr, 'mercatorCorners:', self.mercatorCorners
            corners2 = [
                self.transform.reverse(corner)
                for corner in self.mercatorCorners
            ]
            print >> sys.stderr, 'zip:', zip(corners, corners2)
            for i, pair in enumerate(zip(corners, corners2)):
                c1, c2 = pair
                print >> sys.stderr, i, numpy.array(c1) - numpy.array(c2)

        imageEdgePoints = fillEdges(corners, 5)
        self.mercatorEdgePoints = [
            self.transform.forward(edgePoint) for edgePoint in imageEdgePoints
        ]

        bounds = Bounds()
        for edgePoint in self.mercatorEdgePoints:
            bounds.extend(edgePoint)

        self.maxZoom = calculateMaxZoom(bounds, self.image)
        self.tileBounds = {}
コード例 #2
0
ファイル: quadTree.py プロジェクト: GGSN/geocamTiePoint
    def __init__(self, quadTreeId, image, transformDict):
        self.quadTreeId = quadTreeId
        self.image = image
        self.transform = transform.makeTransform(transformDict)

        corners = getImageCorners(self.image)
        self.mercatorCorners = [self.transform.forward(corner)
                                for corner in corners]

        if 0:
            # debug getProjectiveInverse
            print >> sys.stderr, 'mercatorCorners:', self.mercatorCorners
            corners2 = [self.transform.reverse(corner)
                        for corner in self.mercatorCorners]
            print >> sys.stderr, 'zip:', zip(corners, corners2)
            for i, pair in enumerate(zip(corners, corners2)):
                c1, c2 = pair
                print >> sys.stderr, i, numpy.array(c1) - numpy.array(c2)

        imageEdgePoints = fillEdges(corners, 5)
        self.mercatorEdgePoints = [self.transform.forward(edgePoint)
                                   for edgePoint in imageEdgePoints]

        bounds = Bounds()
        for edgePoint in self.mercatorEdgePoints:
            bounds.extend(edgePoint)

        self.maxZoom = calculateMaxZoom(bounds, self.image)
        self.tileBounds = {}
コード例 #3
0
    def findNearbyManualResults(self, timestamp, maxTimeDiff, missionIn=None):
        '''Find all manual registration results near a certain time.'''

        # Fetch results from manual table in the DB
        results = dict()
        cmd = (
            'SELECT over.extras, image.issMRF FROM geocamTiePoint_overlay over'
            + ' INNER JOIN geocamTiePoint_imagedata image' +
            ' ON over.imageData_id = image.id')
        print cmd
        rows = self._executeCommand(cmd)

        TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
        timeIn = datetime.datetime.strptime(timestamp, TIME_FORMAT)

        # Check each result for time distance
        for row in rows:
            try:
                # Restrict to the mission if it was provided
                mission, roll, frame = self._MRFToMissionRollFrame(row[1])
                if missionIn and (mission != missionIn):
                    continue

                # Unpack all the text data
                data = json.loads(row[0])

                # Convert and compare the timestamps
                acqDate = data['acquisitionDate']
                acqTime = data['acquisitionTime']
                timeString = acqDate.replace('/', '-') + ' ' + acqTime
                timeRow = datetime.datetime.strptime(timeString, TIME_FORMAT)
                diffSeconds = abs((timeIn - timeRow).total_seconds())
                print row[1] + ' --> ' + str(diffSeconds / 60.0)
                if diffSeconds > maxTimeDiff:
                    continue

                # If the time is in range then we will use the result
                confidence = registration_common.CONFIDENCE_HIGH
                imageToProjectedTransform = transform.makeTransform(
                    data['transform'])
                (imageInliers,
                 gdcInliers) = self.parseManualEntryPointPairs(data)

                results[frame] = (imageToProjectedTransform, confidence,
                                  imageInliers, gdcInliers)
            except:  # For now just ignore failing entries
                pass
        return results
コード例 #4
0
ファイル: views.py プロジェクト: GGSN/geocamTiePoint
def overlayIdJson(request, key):
    if request.method == 'GET':
        overlay = get_object_or_404(Overlay, key=key)
        return HttpResponse(dumps(overlay.jsonDict), content_type='application/json')
    elif request.method in ('POST', 'PUT'):
        overlay = get_object_or_404(Overlay, key=key)
        overlay.jsonDict = json.loads(request.raw_post_data)
        transformDict = overlay.extras.get('transform')
        if transformDict:
            overlay.extras.bounds = (quadTree.imageMapBounds
                                     (overlay.extras.imageSize,
                                      transform.makeTransform(transformDict)))
            overlay.generateAlignedQuadTree()
        overlay.save()
        return HttpResponse(dumps(overlay.jsonDict), content_type='application/json')
    elif request.method == 'DELETE':
        get_object_or_404(Overlay, pk=key).delete()
        return HttpResponse("OK")
    else:
        return HttpResponseNotAllowed(['GET', 'POST', 'PUT', 'DELETE'])
コード例 #5
0
 def reversePts(self, toPts):
     """
     Helper needed for fitRpcToModel. 
     Does v = T(u).
         @v is a 3 x n matrix of n 3D points in WGS84 (lon, lat, alt)
         @u is a 2 x n matrix of n 2D points in image (px, py)
     """
     transformDict  = json.loads(self.transform)
     tform =  transform.makeTransform(transformDict)
     pixels = None
     for column in toPts.T:
         # convert column (3D pts in WGS84) to gmap meters
         lonlat = column[:2]
         gmap_meters = transform.lonLatToMeters(lonlat)
         px, py = tform.reverse(gmap_meters)
         newCol = np.array([[px],[py]])
         if pixels is None:
             pixels = newCol
         else:
             pixels = np.column_stack((pixels, newCol))
     return pixels        
コード例 #6
0
    def generateGeotiffExport(self, exportName, metaJson, slug):
        """
        This generates a geotiff from RPC.
        """
        overlay = Overlay.objects.get(alignedQuadTree = self)
        imageSizeType = overlay.imageData.sizeType
        now = datetime.datetime.utcnow()
        timestamp = now.strftime('%Y-%m-%d-%H%M%S-UTC')
        
        # get image width and height
        imageWidth = overlay.imageData.width
        imageHeight = overlay.imageData.height
        
        # update the center point with current transform and use those values
        transformDict  = overlay.extras.transform
        tform =  transform.makeTransform(transformDict)
        center_meters = tform.forward([imageWidth / 2, imageHeight / 2])
        clon, clat  = transform.metersToLatLon(center_meters)
        # get the RPC values 
        T_rpc = rpcModel.fitRpcToModel(self.reversePts, 
                                     imageWidth, imageHeight,
                                     clon, clat)
        srs = gdalUtil.EPSG_4326
        # get original image
        imgPath = overlay.getRawImageData().image.url.replace('/data/', settings.DATA_ROOT)
        # reproject and tar the output tiff
        geotiffExportName = exportName + ('-%s-geotiff_%s' % (imageSizeType, timestamp))
        geotiffFolderPath = settings.DATA_ROOT + 'geocamTiePoint/export/' + geotiffExportName
        dosys('mkdir %s' % geotiffFolderPath)

        fullFilePath = geotiffFolderPath + '/' + geotiffExportName +'.tif'
        gdalUtil.reprojectWithRpcMetadata(imgPath, T_rpc.getVrtMetadata(), srs, fullFilePath)

        geotiff_writer = quadTree.TarWriter(geotiffExportName)
        arcName = geotiffExportName + '.tif'
        geotiff_writer.writeData('meta.json', dumps(metaJson))
        geotiff_writer.addFile(fullFilePath, geotiffExportName + '/' + arcName)  # double check this line (second arg may not be necessary)
        self.geotiffExportName = '%s.tar.gz' % geotiffExportName
        self.geotiffExport.save(self.geotiffExportName,
                                ContentFile(geotiff_writer.getData()))
コード例 #7
0
ファイル: views.py プロジェクト: imclab/geocamTiePoint
def overlayIdJson(request, key):
    if request.method == 'GET':
        overlay = get_object_or_404(Overlay, key=key)
        return HttpResponse(dumps(overlay.jsonDict),
                            content_type='application/json')
    elif request.method in ('POST', 'PUT'):
        overlay = get_object_or_404(Overlay, key=key)
        overlay.jsonDict = json.loads(request.raw_post_data)
        transformDict = overlay.extras.get('transform')
        if transformDict:
            overlay.extras.bounds = (quadTree.imageMapBounds(
                overlay.extras.imageSize,
                transform.makeTransform(transformDict)))
            overlay.generateAlignedQuadTree()
        overlay.save()
        return HttpResponse(dumps(overlay.jsonDict),
                            content_type='application/json')
    elif request.method == 'DELETE':
        get_object_or_404(Overlay, pk=key).delete()
        return HttpResponse("OK")
    else:
        return HttpResponseNotAllowed(['GET', 'POST', 'PUT', 'DELETE'])