Ejemplo n.º 1
0
def getGridLine(srcUtm, dstUtm, clipLines):
    slat, slon = usng.UTMtoLL(*srcUtm)
    tlat, tlon = usng.UTMtoLL(*dstUtm)
    return ("""
<Placemark>
  <LineString>
    <tessellate>1</tessellate>
    <altitudeMode>clampToGround</altitudeMode>
    <coordinates>
%(slon).6f,%(slat).6f,0
%(tlon).6f,%(tlat).6f,0
    </coordinates>
  </LineString>
</Placemark>
""" % dict(slat=slat, slon=slon, tlat=tlat, tlon=tlon))
Ejemplo n.º 2
0
def getRegion(utmSW, utmNE, utmZone, utmLatBand):
    south, west = usng.UTMtoLL(utmSW[0], utmSW[1], utmZone, utmLatBand)
    north, east = usng.UTMtoLL(utmNE[0], utmNE[1], utmZone, utmLatBand)
    return ("""
<Region>
  <LatLonAltBox>
    <north>%(north).6f</north>
    <south>%(south).6f</south>
    <east>%(east).6f</east>
    <west>%(west).6f</west>
  </LatLonAltBox>
  <Lod>
    <minLodPixels>384</minLodPixels>
  </Lod>
</Region>
""" % dict(north=north, south=south, east=east, west=west))
Ejemplo n.º 3
0
def makeGridLinesBlock(opts,
                       parentFile,
                       utmZone,
                       utmLatBand,
                       bounds,
                       i,
                       j,
                       x0,
                       y0,
                       resIndex,
                       skipEdges=False):
    #print 'makeGridLinesBlock %s %s %s %s %s %s' % (utmZone, utmLatBand, bounds, x0, y0, resIndex)
    blockSize = GRIDS[resIndex][0]
    res, style = GRIDS[resIndex + 1]
    n = int(blockSize / res + 1e-5)
    #print '%s %s' % (res, n)

    xmax = x0 + n * res
    ymax = y0 + n * res

    for bound in bounds:
        if not bound.blockMightBeInBounds([x0, y0], [xmax, ymax]):
            if opts.verbose:
                print >> sys.stderr, 'out of bounds 1:'
                print >> sys.stderr, '   bound %s..%s %s..%s' % (
                    bound.s[0], bound.t[0], bound.s[1], bound.t[1])
                print >> sys.stderr, '   block %s..%s %s..%s' % (x0, xmax, y0,
                                                                 ymax)
            return ''

    content = ''
    for k in xrange(0, n + 1):
        if skipEdges and k in (0, n):
            continue
        x = x0 + k * res
        seg = LineSegment([x, y0], [x, ymax], utmZone, utmLatBand)
        for bound in bounds:
            seg.clip(bound)
        content += seg.getPlacemark(**style)

    for k in xrange(0, n + 1):
        if skipEdges and k in (0, n):
            continue
        y = y0 + k * res
        seg = LineSegment([x0, y], [xmax, y], utmZone, utmLatBand)
        for bound in bounds:
            seg.clip(bound)
        content += seg.getPlacemark(**style)

    thisFile = os.path.join(os.path.dirname(parentFile), '%s_%s' % (i, j),
                            'a.kml')

    for ii in xrange(0, n):
        x = x0 + ii * res
        for jj in xrange(0, n):
            y = y0 + jj * res

            addMarker = not (skipEdges and ii == 0 and jj == 0)
            for bound in bounds:
                if not bound.inBounds([x, y]):
                    addMarker = False

            if addMarker:
                lat, lon = usng.UTMtoLL(x, y, utmZone, utmLatBand)
                precision = 5 - int(math.floor(math.log10(res)))
                usngCoords = usng.UTMtoUSNG(x, y, utmZone, utmLatBand,
                                            precision)
                latDir = 'N' if lat >= 0 else 'S'
                lonDir = 'E' if lon >= 0 else 'W'
                description = (
                    'USNG: %s<br/>\n' % usngCoords + 'Lat/lon:<br/>\n' +
                    '%.6f, %.6f<br/>\n' % (lat, lon) + '%s %s, %s %s<br/>\n' %
                    (degMinString(lat), latDir, degMinString(lon), lonDir) +
                    '%s %s, %s %s<br/>\n' % (degMinSecString(lat), latDir,
                                             degMinSecString(lon), lonDir))
                description = urllib.quote(description)
                icon = os.path.relpath(os.path.join(outDirG, 'corner.png'),
                                       os.path.dirname(thisFile))
                content += ("""
<Placemark>
  <Point>
    <coordinates>%(lon).6f,%(lat).6f</coordinates>
  </Point>
  <Style>
    <IconStyle>
      <Icon>
        <href>%(icon)s</href>
      </Icon>
      <heading>0</heading>
      <scale>0.3</scale>
      <hotSpot x="0.0" y="0.0" xunits="fraction" yunits="fraction"/>
    </IconStyle>
  </Style>
  <description><![CDATA[%(description)s]]></description>
</Placemark>
""" % dict(lat=lat, lon=lon, icon=icon, description=description))
            if (resIndex + 2) < len(GRIDS):
                # recurse
                content += makeGridLinesBlock(opts,
                                              thisFile,
                                              utmZone,
                                              utmLatBand,
                                              bounds,
                                              ii,
                                              jj,
                                              x,
                                              y,
                                              resIndex + 1,
                                              skipEdges=True)

    region = getRegion([x0, y0], [xmax, ymax], utmZone, utmLatBand)

    return makeNetworkLink(parentFile, thisFile, content, region)
Ejemplo n.º 4
0
 def getPlacemark(self, **kwargs):
     if not self.visible:
         return ''
     slatlon = usng.UTMtoLL(self.s[0], self.s[1], self.zone, self.latBand)
     tlatlon = usng.UTMtoLL(self.t[0], self.t[1], self.zone, self.latBand)
     return getLineString(slatlon, tlatlon, **kwargs)