def cluster(targetLocationPath, probabilityPath, iterationCountPerBurst, maximumGeoDiameter, minimumGeoDiameter): # Initialize probabilityInformation = probability_store.Information(probabilityPath) imagePath = probabilityInformation.getImagePath() imageInformation = image_store.Information(imagePath) multispectralImage = imageInformation.getMultispectralImage() multispectralGeoTransform = multispectralImage.getGeoTransform() spatialReference = multispectralImage.getSpatialReference() # Convert maximumGeoDiameter into maximumPixelDiameter maximumPixelDiameter = max( image_store.convertGeoDimensionsToPixelDimensions( maximumGeoDiameter, maximumGeoDiameter, multispectralGeoTransform ) ) # Convert minimumGeoDiameter into minimumPixelDiameter minimumPixelDiameter = max( image_store.convertGeoDimensionsToPixelDimensions( minimumGeoDiameter, minimumGeoDiameter, multispectralGeoTransform ) ) # Load pixelDimensions windowGeoLength = probabilityInformation.getWindowLengthInMeters() pixelWidth, pixelHeight = image_store.convertGeoDimensionsToPixelDimensions( windowGeoLength, windowGeoLength, multispectralGeoTransform ) # Cluster probabilityPacks = probability_store.load(probabilityPath) vectors = [(x, y, probability) for x, y, label, probability in probabilityPacks if label == 1] windowLocations = grapeCluster(vectors, iterationCountPerBurst, maximumPixelDiameter, minimumPixelDiameter) windowCenters = [(xy[0] + pixelWidth / 2, xy[1] + pixelHeight / 2) for xy in windowLocations] geoCenters = image_store.convertPixelLocationsToGeoLocations(windowCenters, multispectralGeoTransform) # Save point_store.save(targetLocationPath, geoCenters, spatialReference)
def saveShapefile(targetPath, sourceProbabilityPath, multispectralImage, windowLengthInMeters): # Get pixelDimensions windowPixelWidth, windowPixelHeight = multispectralImage.convertGeoDimensionsToPixelDimensions(windowLengthInMeters, windowLengthInMeters) # Load positiveProbabilityPacks positiveProbabilityPacks = load(sourceProbabilityPath, withNegative=False) # Center positivePixelCenters = [(x[0] + windowPixelWidth / 2, x[1] + windowPixelHeight / 2) for x in positiveProbabilityPacks] # Convert positiveGeoCenters = multispectralImage.convertPixelLocationsToGeoLocations(positivePixelCenters) # Save point_store.save(targetPath, positiveGeoCenters, multispectralImage.getSpatialReference())
def buildPatch( targetPatchPath, pixelCenters, actualPixelPointMachine, multispectralImage, panchromaticImage, windowLengthInMeters ): # Set paths targetPositivePath = targetPatchPath + "_positive" targetNegativePath = targetPatchPath + "_negative" # Label positivePatchPixelCenters, negativePatchPixelCenters = labelPixelCenters(pixelCenters, actualPixelPointMachine) # Convert positivePatchGeoCenters = multispectralImage.convertPixelLocationsToGeoLocations(positivePatchPixelCenters) negativePatchGeoCenters = multispectralImage.convertPixelLocationsToGeoLocations(negativePatchPixelCenters) # Save spatialReference = multispectralImage.getSpatialReference() point_store.save(targetPositivePath, positivePatchGeoCenters, spatialReference) point_store.save(targetNegativePath, negativePatchGeoCenters, spatialReference) # Extract window_process.extract( targetPositivePath, positivePatchGeoCenters, 1, windowLengthInMeters, multispectralImage, panchromaticImage ) window_process.extract( targetNegativePath, negativePatchGeoCenters, 0, windowLengthInMeters, multispectralImage, panchromaticImage ) # Combine return sample_process.combineDatasets(targetPatchPath, [targetPositivePath, targetNegativePath])
def save(fileName, points): targetPath = os.path.join(targetFolderPath, fileName) point_store.save(targetPath, points, spatialReference)
XY_Shoreline = geo_rect_func.rotate_translate( np.asarray(XY_shor_und[:, 0, 0], dtype='float64'), np.asarray(XY_shor_und[:, 0, 1], dtype='float64'), rotation=None, translation=tuple(translation)) #saving real-world coordinates of shoreline xy_srl = zip(list(XY_Shoreline[0]), list(XY_Shoreline[1])) try: shrl_name = sys.argv[3] except: shrl_name = str(shl + '.shp') print 'File shoreline shp saved to', shrl_name #point_store.save(shrl_name,xy_srl,'+proj=utm +zone=33 +ellps=WGS84 +datum=WGS84 +units=m +no_defs ') point_store.save( shrl_name, xy_srl, '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs ' ) reader = shapefile.Reader(shrl_name) fields = reader.fields[1:] field_names = [field[0] for field in fields] buffer = [] for sr in reader.shapeRecords(): atr = dict(zip(field_names, sr.record)) geom = sr.shape.__geo_interface__ asa = geom.values() buffer.append(asa[-1]) try: json_shrl_name = sys.argv[4] except: json_shrl_name = str(shrl_name + '.json')
def saveshp(fn, points, proj4): point_store.save(fn, points, proj4) print "saved as ", fn