def buildPolygon(m, mgrs=None, mgrsPrecision=10): ''' Builds a polygon that represents the mgrs box. NOT TESTED ''' # Get the SW corner Lat and Lon swLat, swLon = m.toLatLon(str(mgrs)) # Extending a vector into the other cells to retrieve their coords and then mgrs offSetMultiplier = 1.5 # Get the sidelength of 1 cell and extends it to ensure the checking vector hits inside the adjacent cell displacement = (Geographic.getMgrsPrecision(mgrsPrecision)) displacement *= offSetMultiplier # Determine the cell side length from MGRS precision latScale, lonScale = Geographic.radialToLinearUnits(swLat) scale = 1.0/latScale displacement = float(displacement) * float(scale) nLat, nLon = getAdjacentCellCoords(m, mgrsPrecision, swLat, swLon, 10.0, displacement) neLat, neLon = getAdjacentCellCoords(m, mgrsPrecision, swLat, swLon, 45.0, displacement) eLat, eLon = getAdjacentCellCoords(m, mgrsPrecision, swLat, swLon, 80.0, displacement) coords = [[swLon, swLat], [nLon, nLat], [neLon, neLat], [eLon, eLat], [swLon, swLat]] return coords
def getMGRS(self, precision=10): ''' Converts the geos to MGRS. The optional precision determines the number of figures for the MGRS conversion. Tests written.''' utm = Geographic.geo2Utm(self.lat, self.lon) mgrs = Geographic.utm2Mgrs(utm[0], utm[1], utm[2], precision) return mgrs
def testMgrsToLonLat(self): ''' Checks the conversion from MGRS to UTM. ''' f10 = "36TXR0937739450" f8 = "36TXR09373945" f6 = "36TXR093394" f4 = "36TXR0939" f2 = "36TXR03" fs = [f10, f8, f6, f4, f2] for mgrs in fs: lat, lon = Geographic.mgrsToLonLat(mgrs) print lat, lon
def testGeo2Mgrs(self): ''' ''' lat = 45.5 lon = 34.4 #retrieve UTM zone, easting, northing = Geographic.geo2Utm(lat, lon) mgrs = Geographic.utm2Mgrs(zone, easting, northing, d=10) print "10 fig", mgrs mgrs = Geographic.utm2Mgrs(zone, easting, northing, d=8) print "8 fig", mgrs mgrs = Geographic.utm2Mgrs(zone, easting, northing, d=6) print "6 fig", mgrs mgrs = Geographic.utm2Mgrs(zone, easting, northing, d=4) print "4 fig", mgrs mgrs = Geographic.utm2Mgrs(zone, easting, northing, d=2) print "2 fig", mgrs
settings = SettingFileReader() print settings.getAutoGeoBox() print settings.getNorthBorder() print settings.getSouthBorder() print settings.getWestBorder() print settings.getEastBorder() print settings.getPixelPerDegree() print settings.getStrokeWidth() print settings.getStrokeColor() geox = Geographic() geox.setGpxFile("") geox.guessBoundingBox() geox.printGeoBox() geox.computeOutputImageSize(settings.getPixelPerDegree()) print("\n") geox.printOutputImageSize() print("\n") #allSegments = geox.preparePolylines() allSegments = geox.preparePolylinesTuples() # --------------- to put in a clasee!