Hey, somebody discovered __geo_interface__. If you'd rather use Python's standard json module than geojson, you'll need to implement a custom encoder as documented:
>>> import json >>> class GeoEncoder(json.JSONEncoder): ... def default(self, obj): ... if hasattr(obj, '__geo_interface__'): ... return obj.__geo_interface__ ... return json.JSONEncoder.default(self, obj) ... >>> class GeoThing(object): ... __geo_interface__ = {'type': 'Point', 'coordinates': [0.0, 0.0]} ... >>> json.dumps(GeoThing(), cls=GeoEncoder) '{"type": "Point", "coordinates": [0.0, 0.0]}'
The geojson module does this for you, and more, but clearly needs to work with json from 2.6 as well as simplejson.
Comments: 1
The Geojson, Rtree, Shapely, and OWSLib packages all originated in Pleiades, a digital project sponsored by the NEH Office of Digital Humanities, and run out of, first, the University of North Carolina's Ancient World Mapping Center, and, now, New York University's Institute for the Study of the Ancient World. All but Shapely are now at least partially lead by developers not at AWMC or ISAW. I'm proud of the fact that elements of Pleiades are being reused by different developers in new contexts, and plan to make their utility and broad appeal a part of future proposals for the development of geographic applications in the digital humanities. I'd like to see other stakeholders making similar appeals.
Are these packages important to you and your company or organization? Do you appreciate them? If so, kindly consider sharing your appreciation with the internet community and potential sponsors therein by writing a short blurb on our wiki. It's the next best thing to blogging fanatically about them. Thanks!
Comments: 1
Another bug fix in http://pypi.python.org/pypi/Rtree/0.4.3. Do upgrade when you can. No need to upgrade the spatialindex lib.
Comments: 0
Speaking of the recovery.gov overhaul, Erik Wilde has been digging into recovery.gov from the start and has some excellent recommendations for open, transparent architecture. It's essential reading, and entirely apart from the private vs. public foodfight that Darrell Issa is engaged in.
A few years ago, I would have said that ESRI was genetically incapable of implementing an open, transparent architecture. The original Geospatial One Stop made a mockery of the web (and remains so). But there have been some signs that things are changing: bookmarkable search results, OpenSearch descriptions discoverable via links in http://geoss.esri.com/geoportal/catalog/main/home.page, Atom feeds with GeoRSS elements. It's no longer a laughable proposition.
Comments: 3
I mentioned a Format/Atom.js file in the previous post. I've overhauled some older code so that it conforms almost completely to RFC 4287 and submitted a patch for OpenLayers: #1366. Download it into a buildout and you can patch it into the latest and greatest OpenLayers like this:
[buildout]
parts = openlayers-format-atom
[openlayers-format-atom]
recipe = zgeo.recipe.openlayers
url = http://openlayers.org/download/OpenLayers-2.8-rc5.tar.gz
patches =
format-atom.patch
include =
OpenLayers/Format/Atom.js
The format's tests give a pretty good overview of its capabilities:
// write entry 6: Atom links function test_Format_Atom_writeentry6(t) { t.plan(1); // Feature attributes in Atom namespace var atomAttrib = { title: "Atom test", summary: "An Atom testing feature", updated: "2009-06-02T10:00:00Z", links: [ { href: "http://example.com/blog/1", rel: "alternate" } ] }; var fx = new OpenLayers.Feature.Vector(null, {atom: atomAttrib}); fx.fid = 'urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed'; var writer = new OpenLayers.Format.Atom(); var data = writer.write(fx); t.xml_eq( data, // begin document '<entry xmlns="http://www.w3.org/2005/Atom">' + '<id>urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed</id>' + '<link href="http://example.com/blog/1" rel="alternate"/>' + '<summary>An Atom testing feature</summary>' + '<title>Atom test</title>' + '<updated>2009-06-02T10:00:00Z</updated>' + '</entry>', // end document 'Writes an entry doc with Atom constructs and links' ); } // write out point -- just enough to see that we're getting the // georss:where element with a Point. We'll trust GML.v3 to get the // details right. function test_Format_Atom_writepoint(t) { t.plan(1); var point = new OpenLayers.Geometry.Point(-111.04, 45.68); var fx = new OpenLayers.Feature.Vector(point, {}); fx.fid = 'urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed'; var writer = new OpenLayers.Format.Atom(); var data = writer.write(fx); t.xml_eq( data, // begin document '<entry xmlns="http://www.w3.org/2005/Atom">' + '<id>urn:uuid:82ede847-b31a-4e3d-b773-7471bad154ed</id>' + '<title>undefined</title>' + '<georss:where xmlns:georss="http://www.georss.org/georss">' + ' <gml:Point xmlns:gml="http://www.opengis.net/gml">' + ' <gml:pos>45.68 -111.04</gml:pos>' + ' </gml:Point>' + '</georss:where>' + '</entry>', // end document 'Writes an entry doc with a point location' ); }
The patch brings a few new constructs to OpenLayers: Atom categories, persons, and links as javascript objects. The latter have been expressed before in Subbu's blog (http://www.subbu.org/blog/2008/10/generalized-linking), and the former follow. An atom namespace is introduced into a features attributes object to minimize collisions or confusion with other formats (link in GeoRSS.js).
Writing a feature to Atom format is the hard part. Posting to an AtomPub service is easy. With jQuery:
var entry = new OpenLayers.Feature.Vector(geom, data); var writer = new OpenLayers.Format.Atom(); $.ajax({ async: false, type: "POST", url: $("link[rel=service]").attr("href"), data: writer.write(entry), processData: false, success: function(msg) { alert( "Data Saved: " + msg ); }, beforeSend: function(req) { req.setRequestHeader("Slug", slug); } });
Comments: 0
I've just uploaded my first zc.buildout recipe to PyPI: http://pypi.python.org/pypi/zgeo.recipe.openlayers/. It's a recipe for creating custom builds of OpenLayers.js. Based on Kai Lautaportti's hexagonit.recipe.cmmi, it does some of the same useful tricks: working on either OpenLayers distributions (by url option) or local checkouts (by path option), and code patching (by patch-options and patches). Put a list of files in the include option, following the OpenLayers documentation for custom build profiles, and crank out the custom compressed files.
I've put it to use in a project that implements nothing other than the Atom publishing protocol. No layers, no WxS, no strategies. My custom profile buildout configuration is very simple:
[buildout]
parts = openlayers-bingo
[openlayers-bingo]
recipe = zgeo.recipe.openlayers
path = ${buildout:directory}/src/openlayers
include =
OpenLayers/Format/Atom.js
OpenLayers/Format/GeoJSON.js
Running it generates the output you may have seen before:
$ bin/buildout -c buildout.cfg Uninstalling openlayers-bingo. Installing openlayers-bingo. openlayers-bingo: Using local source directory: /Users/seang/code/ol-recipes/src/openlayers Merging libraries. Importing: OpenLayers.js Importing: OpenLayers/BaseTypes.js Importing: OpenLayers/SingleFile.js Importing: OpenLayers/Util.js Importing: OpenLayers/BaseTypes/Class.js Importing: OpenLayers/Format/Atom.js Importing: OpenLayers/Format/GeoJSON.js Resolution pass 1... Importing: OpenLayers/BaseTypes/Bounds.js Importing: OpenLayers/BaseTypes/Element.js Importing: OpenLayers/BaseTypes/LonLat.js Importing: OpenLayers/BaseTypes/Pixel.js Importing: OpenLayers/BaseTypes/Size.js Importing: OpenLayers/Console.js Importing: OpenLayers/Feature/Vector.js Importing: OpenLayers/Format/GML/v3.js Importing: OpenLayers/Format/JSON.js Importing: OpenLayers/Format/XML.js Importing: OpenLayers/Geometry/LineString.js Importing: OpenLayers/Geometry/MultiLineString.js Importing: OpenLayers/Geometry/MultiPoint.js Importing: OpenLayers/Geometry/MultiPolygon.js Importing: OpenLayers/Geometry/Point.js Importing: OpenLayers/Geometry/Polygon.js Importing: OpenLayers/Lang/en.js Resolution pass 2... Importing: OpenLayers/Feature.js Importing: OpenLayers/Format.js Importing: OpenLayers/Format/GML/Base.js Importing: OpenLayers/Geometry.js Importing: OpenLayers/Geometry/Collection.js Importing: OpenLayers/Geometry/Curve.js Importing: OpenLayers/Geometry/LinearRing.js Importing: OpenLayers/Lang.js Resolution pass 3... Importing: OpenLayers/Format/GML.js Importing: OpenLayers/Format/WKT.js Importing: OpenLayers/Marker.js Importing: OpenLayers/Popup/AnchoredBubble.js Resolution pass 4... Importing: OpenLayers/Events.js Importing: OpenLayers/Icon.js Importing: OpenLayers/Popup/Anchored.js Resolution pass 5... Importing: OpenLayers/Popup.js Re-ordering files... Exporting: OpenLayers/SingleFile.js Exporting: OpenLayers.js Exporting: OpenLayers/BaseTypes.js Exporting: OpenLayers/BaseTypes/Class.js Exporting: OpenLayers/Util.js Exporting: OpenLayers/BaseTypes/Element.js Exporting: OpenLayers/BaseTypes/Size.js Exporting: OpenLayers/Console.js Exporting: OpenLayers/Icon.js Exporting: OpenLayers/Popup.js Exporting: OpenLayers/BaseTypes/Bounds.js Exporting: OpenLayers/BaseTypes/LonLat.js Exporting: OpenLayers/BaseTypes/Pixel.js Exporting: OpenLayers/Lang.js Exporting: OpenLayers/Popup/Anchored.js Exporting: OpenLayers/Events.js Exporting: OpenLayers/Format.js Exporting: OpenLayers/Lang/en.js Exporting: OpenLayers/Popup/AnchoredBubble.js Exporting: OpenLayers/Format/JSON.js Exporting: OpenLayers/Format/XML.js Exporting: OpenLayers/Marker.js Exporting: OpenLayers/Feature.js Exporting: OpenLayers/Feature/Vector.js Exporting: OpenLayers/Format/WKT.js Exporting: OpenLayers/Geometry.js Exporting: OpenLayers/Geometry/Collection.js Exporting: OpenLayers/Geometry/Point.js Exporting: OpenLayers/Geometry/MultiPoint.js Exporting: OpenLayers/Geometry/Curve.js Exporting: OpenLayers/Geometry/LineString.js Exporting: OpenLayers/Geometry/LinearRing.js Exporting: OpenLayers/Geometry/MultiLineString.js Exporting: OpenLayers/Geometry/Polygon.js Exporting: OpenLayers/Geometry/MultiPolygon.js Exporting: OpenLayers/Format/GML.js Exporting: OpenLayers/Format/GeoJSON.js Exporting: OpenLayers/Format/GML/Base.js Exporting: OpenLayers/Format/GML/v3.js Exporting: OpenLayers/Format/Atom.js Total files merged: 40 Compressing using jsmin. Adding license file. Writing to OpenLayers.js. Done.
And yields these files, ready to be copied or linked to a location for production:
$ ls -l parts/openlayers-bingo/ total 360 -rw-r--r-- 1 seang staff 180958 Jun 3 15:35 OpenLayers.js drwxr-xr-x 25 seang staff 850 Jun 3 15:23 img drwxr-xr-x 3 seang staff 102 Jun 3 15:23 theme
Oh, and collective.checkdocs is great for finding bugs in your package's long descriptions.
Comments: 0
I'm using zc.buildout to deploy ZEO, Plone, nginx, Varnish, and supervisord (not to mention GEOS, spatialindex, libxml2), reproducibly, from a few configuration files. More interesting to my readers, I suspect, is Bertrand Mathieu's configuration for building out Django, Solr, and supervisord.
Comments: 0
This release includes a bug fix and, thanks to Howard Butler's libLAS-driven work, new Windows installers for Pythons 2.4-2.6 including the latest and greatest spatialindex DLL.
Comments: 0
Some rights reserved 2008 by Sean Gillies.