Fri, 28 Jan 2011

Potsdam Mapping Party

I'm holding my first mapping party in Potsdam, at First Crush on Saturday January 31st between 11AM and 4PM. A mapping party is an informal social get-together where people can learn more about OpenStreetMap, explore their community, and share their findings with other people. OpenStreetMap is a community-created free, open public map. If you don't know why one such is needed, well, come to the party and I'll explain!

More info is on the OpenStreetMap wiki.

Posted [15:55] [Filed in: osm] [permalink] [Google for the title] [Tags ] [digg this]
qrcode

US WMS

JOSM doesn't support WMS Capabilities, so I created a crutch for it. These two programs (the first calls into the second) create three files for each state. One is the capabilities file downloaded from Seamless. Another one contains just the WMS URLs. Another one is an OSM file containing bounding boxes for each of the WMS layers. Load it into JOSM to see what layers cover what.

I find that it's helpful to initially turn on a WMS layer while zoomed out enough to see the entire bounding box. You get a very low resolution layer, but you can see if it overlaps your area of interest. Then you can zoom in enough, right-click on the layer name in the Layers box, and selecte "Change Resolution" to get a nicely rendered layer.

#!/usr/bin/python

# pulled by hand from http://seamless.usgs.gov/wms_services.php?layerid=15
all = """USGS_EDC_Ortho_Coastal	http://ims.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Coastal?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_StateLocal	http://ims.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_StateLocal?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Urban	http://ims.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Urban?REQUEST=capabilities&SERVICE=WMS
BLM_Ortho	http://ims.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/BLM_Ortho?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_NYSDOP_Grid	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_NYSDOP_Grid?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Alabama	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Alabama?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Alaska	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Alaska?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Arizona	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Arizona?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Arkansas	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Arkansas?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_California	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_California?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Colorado	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Colorado?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Connecticut	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Connecticut?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Delaware	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Delaware?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_DistrictOfColumbia	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_DistrictOfColumbia?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Florida	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Florida?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Georgia	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Georgia?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Hawaii	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Hawaii?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Idaho	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Idaho?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Illinois	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Illinois?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Indiana	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Indiana?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Iowa	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Iowa?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Kansas	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Kansas?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Kentucky	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Kentucky?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Louisiana	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Louisiana?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Maine	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Maine?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Maryland	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Maryland?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Massachusetts	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Massachusetts?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Mexico	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Mexico?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Michigan	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Michigan?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Minnesota	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Minnesota?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Mississippi	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Mississippi?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Missouri	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Missouri?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Montana	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Montana?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Nebraska	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Nebraska?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Nevada	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Nevada?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_NewHampshire	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_NewHampshire?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_NewJersey	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_NewJersey?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_NewMexico	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_NewMexico?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_NewYork	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_NewYork?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_NorthCarolina	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_NorthCarolina?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_NorthDakota	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_NorthDakota?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Ohio	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Ohio?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Oklahoma	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Oklahoma?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Oregon	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Oregon?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Pennsylvania	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Pennsylvania?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_PuertoRico	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_PuertoRico?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_RhodeIsland	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_RhodeIsland?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_SouthCarolina	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_SouthCarolina?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_SouthDakota	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_SouthDakota?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Tennessee	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Tennessee?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Texas	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Texas?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Utah	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Utah?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Vermont	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Vermont?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Virginia	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Virginia?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Washington	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Washington?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_WestVirginia	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_WestVirginia?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Wisconsin	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Wisconsin?REQUEST=capabilities&SERVICE=WMS
USGS_EDC_Ortho_Wyoming	http://imsortho.cr.usgs.gov/wmsconnector/com.esri.wms.Esrimap/USGS_EDC_Ortho_Wyoming?REQUEST=capabilities&SERVICE=WMS"""

for one in all.split("\n"):
    state, url = one.split("\t")
    state = state.replace("USGS_EDC_Ortho_", "")
    # if for any reason, you need to run this program twice, comment out the following line
    print "wget -O %s.xml %s" % (state, url)
    print "./capabilities-to-osm.py %s.xml >%s.wms" % (state, state)

capabilities-to-osm.py follows:

#!/usr/bin/python

from xml.sax import saxutils
import sys
import time

class OSM():
    nodenum = -1
    waynum = -1

    def __init__(self, outf=sys.stdout):
        self.outf = outf
        self.outf.write("""<?xml version='1.0' encoding='UTF-8'?>
<osm version='0.6' generator='osmgen'>
""")
        self.startnum = None

    def point(self, x,y):
        self.outf.write("<node id='%d' lat='%s' lon='%s' />\n" % ( self.nodenum, y, x))
        self.nodenum -= 1

    def start(self):
        self.startnum = self.nodenum

    def stop(self, name=None):
        self.outf.write("<way id='%d' visible='true'>\n" % self.waynum)
        self.waynum -= 1
        for n in range(self.startnum, self.nodenum, -1):
            self.outf.write("<nd ref='%d'/>\n" % n)
        self.outf.write("<nd ref='%d'/>\n" % self.startnum)
        self.outf.write("<tag k='area' v='yes'/>\n")
        if name is not None:
            self.outf.write("<tag k='name' v='%s'/>\n" % name)
        self.outf.write("</way>")

    def close(self):
        self.outf.write("</osm>\n")

class print_track(saxutils.XMLFilterBase):
    chars = None
    baseurl = None
    def startElement(self, name, attrs):
        if name == 'LatLonBoundingBox':
        # <LatLonBoundingBox minx="-79.810565637" miny="0" maxx="-71.8388440985" maxy="45.1013683371"/>
            osm.start()
            osm.point(attrs['minx'], attrs['miny'])
            osm.point(attrs['minx'], attrs['maxy'])
            osm.point(attrs['maxx'], attrs['maxy'])
            osm.point(attrs['maxx'], attrs['miny'])
            osm.stop(self.name)
        elif name == 'Name':
            self.chars= ''
        elif name == 'OnlineResource':
            self.baseurl = attrs['xlink:href']
    def characters(self, ch):
        if self.chars is not None:
            self.chars += ch
    def endElement(self, name):
        if name == 'Name':
            self.name = self.chars
            self.chars = ''
            if self.baseurl:
                print "%sservice=WMS&version=1.1.1&request=getmap&width=500&height=500&format=image/png&SRS=EPSG:4326&layers=%s&" % (self.baseurl, self.name)

from xml.sax import make_parser
from xml.sax.handler import feature_namespaces

if __name__ == '__main__':

    import sys
    # Create a parser
    parser = make_parser()


    # Tell the parser we are not interested in XML namespaces
    parser.setFeature(feature_namespaces, 0)

    osm = OSM(open(sys.argv[1].replace('.xml', '.osm'), "w"))

    # Create the handler
    dh = print_track()

    # Tell the parser to use our handler
    parser.setContentHandler(dh)

    # Parse the input
    parser.parse(open(sys.argv[1]))

osm.close()

Posted [15:55] [Filed in: osm] [permalink] [Google for the title] [Tags , ] [digg this]
qrcode