3

I would like to create a world map with interaction on continents created directly from a postgis database.

For the moment, I have a POSTgis database with the data. I created a background with TileMill. I get data from Postgis in SVG and put them on the map using Raphael.

All seem well except that I have a small difference between both map :s I use default projection of TileMill (and I think we can't change it :)). And here is the POSTGIS command I'm executing to get the SVG:

SELECT st_asSVG( 
      st_scale( 
          st_translate( 
              St_Intersection( 
                  ST_Transform(ST_SetSRID(ST_GeomFromText('POLYGON((-151.875 80.6470,175.7812 80.6470,175.7812 -63.2336,-151.875 -63.2336,-151.875 80.6470))'), 4326), 3857), 
              (SELECT st_union(geom) FROM geo.continentboundaries)) 
          , 20037508.72, -20037508.72) 
      , 0.0000199043047125,0.0000199043047125)
    , 0, 0)

Here is the result: https://i.stack.imgur.com/7lS0F.png

Do you know where I have a mistake?

Edit: some precisions: I'm using the same data for Tilemill and the svg. I added in the tilemill project the example of tilemill there is no problem of projection. In the layer in tilemill I'm using 900913. st_srid give me 3857 in Postgis which seems ok? I'm a beginner in SIG

4
  • There may be a lot of reasons why your data is projected in a wrong way. First of all are you sure that data in Postgis is in EPSG:4326? If the datum was not WGS84 (NAD83 may be?) - then you have to use correct EPSG code. I have no experience with TileMill but clearly you can define custom SRS there (mapbox.com/tilemill/docs/guides/postgis-work). Please provide us with information about what SRS is currently used in TileMill in your project. Aug 26, 2012 at 11:56
  • Thanks for your answer. I'm using the same data for Tilemill and the svg. I added in the tilemill project the example of tilemill there is no problem of projection. In the layer in tilemill I'm using 900913. st_srid give me 3857 in Postgis which seems ok? I'm a beginner in SIG... Is there something else I should check?
    – Farf
    Aug 26, 2012 at 12:30
  • Ok, definitely you should add this information to question. Try execute your query without ST_Scale and tell us if there is any difference. Aug 26, 2012 at 14:46
  • Ok I added those information in the question. st_scale doesn't seem to do anything else than multiplying all the data. I don't see an easy solution to show data on a web browser without scaling it before. (scaling a svg with such big numbers doesn't work). I'll try tomorrow with only some points... but I don't have any idea from the source of this problem...
    – Farf
    Aug 26, 2012 at 18:49

2 Answers 2

1

I think that ST_Scale and ST_Translate are the source of your issue. Both of them changes output coordinates of the input data. So initial data (Tliemill undercover) has different coordinates than SVG produced with your query. Instead of scaling you may consider using ST_Simplify function (if I understand your intentions correctly).

I don't know the reason why you want to make PostGIS produce SVG to be shown on map (the way you demonstrated on the screenshot) when TileMill is capable of rendering pure PostGIS data, but if your true issue is in feeding SVG to TileMill (or cashing tiles for rendering speeding) - you should ask separate question.

4
  • Thanks for your answer. I'd like to have interaction with the SVG created. I don't think Tilemill manage that. I'm using Raphaeljs to manage the interaction (mouseover, click...). The objective is to have SVG in pixel. So yes, st_scale and st_translate change coordinates but normally, it doesn't change the "projection"... (I removed st_simplify of the request in the question to make it shorter. but yes in the final query, I'll add it.)
    – Farf
    Aug 27, 2012 at 7:30
  • @Farf, if your coordinates are changed and projection stayed the same, then when you place data with modified coordinates upon the same layer but with no modification of coordinates - coordinates of the same feature will be different in different layers and you will see the picture like you demonstrated here. I believe that your true issue is feeding SVG to Tilemill, so it would encourage you to ask corresponding question. If you use functions like st_scale or st_translate in your example they have to be applied to the undercover too to let both layers stack. Aug 27, 2012 at 8:57
  • ... I'm really sorry, The background image didn't have the bounds I thought... so the command is working well and the image is perfekt. As often the bug wasn't in complex things :s Thanks for you help.
    – Farf
    Aug 27, 2012 at 13:24
  • @Farf, I'm glad you've worked it out! Aug 27, 2012 at 14:32
1

... I'm really sorry, The background image didn't have the bounds I thought... so the command is working well and the image is perfekt. As often the bug wasn't in complex things :s Thanks for you help.

1
  • 1
    @Farf- Go ahead and click the checkmark next to your answer to mark it as accepted to close the question. Thanks. Aug 27, 2012 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.