I used ogr to read the shapefile which goes something like this:

import ogr
feature_data = ogr.Open(path)
for feature in feature_data.GetLayerByIndex(0):
    ogr_geometry = feature.GetGeometryRef()

>From there, depending on what type of geometry it is you can extract
the individual points, or maybe even get the SVG path directly? (but
I'm not sure if it supports that output). Django also has nice
pythonic support and documentation for various geometries so I would
look at this too:

https://docs.djangoproject.com/en/dev/ref/contrib/gis/geos/

-Matt

On Tue, Nov 22, 2011 at 12:38 PM, Anthony Pesce <[email protected]> wrote:
> I'm using Raphael 2.0 on the front end, and what you did sounds perfect. I
> was just using a Python script to process the SVG into JSON anyway.
> How do you do the conversion from the shp file?
>
> On Tue, Nov 22, 2011 at 12:32 PM, Matt Bartolome <[email protected]>
> wrote:
>>
>> Anthony,
>> I was looking for the same thing and ended up rendering my svg paths
>> and attribute data as json then using the Raphael JavaScript Library
>> to render the data on screen. That library is really nice; it has some
>> very handy functions for interacting with SVG path elements, which
>> also can be handled by jquery $(element). It also does svg transforms
>> and matrices in the 2.0 version which really helps when you are trying
>> to draw geographic coordinate based stuff.
>>
>> -Matt
>>
>> On Tue, Nov 22, 2011 at 11:51 AM, Anthony Pesce <[email protected]>
>> wrote:
>> > Hi all,
>> > I'm using Mapnik (702 Python bindings) to convert a shp file to an SVG.
>> > Ultimately, I would like to use the SVG to make an interactive map on
>> > the
>> > web -- but that requires attaching an ID attribute to the SVG path
>> > elements.
>> > It would be great if I could choose one of the attributes from the
>> > polygons
>> > on the shp file to use at the ID for the corresponding path in the SVG,
>> > but
>> > I can't see a way to accomplish this.
>> > Here's the code I'm using to make the SVG:
>> > import mapnik
>> > # Define the projection
>> > prj = "+proj=aea +lat_1=27.5 +lat_2=35 +lat_0=18 +lon_0=-100
>> > +x_0=1500000
>> > +y_0=6000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
>> > # Create the Map
>> > m = mapnik.Map(620, 800, prj)
>> > # Set some basic styling
>> > m.background = mapnik.Color('#ffffff')
>> > s = mapnik.Style()
>> > r = mapnik.Rule()
>> > r.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color('#dddddd')))
>> > r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('#ffffff'),1))
>> > s.rules.append(r)
>> > m.append_style('My Style', s)
>> > # Load in the shp file
>> > shape = mapnik.Shapefile(file='file.shp')
>> > # Setup a layer for our shp file
>> > lyr = mapnik.Layer('US', prj)
>> > # Load the shp onto the map
>> > lyr.datasource = shape
>> > lyr.styles.append('My Style')
>> > m.layers.append(lyr)
>> > m.zoom_to_box(lyr.envelope())
>> > # spit out the SVG
>> > mapnik.render_to_file(m,'US.svg', 'svg')
>> > Thanks,
>> > Anthony Pesce
>> > _______________________________________________
>> > Mapnik-users mailing list
>> > [email protected]
>> > https://lists.berlios.de/mailman/listinfo/mapnik-users
>> >
>> >
>
>
_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users

Reply via email to