Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

im trying to create KML files manually (XML format) by extracting data from a postGIS database with "geography" values in a column.

But i belive i need to transform the projection of each row in the database from EPSG:4326 to EPSG: 900913.. How can i do that?

Code:

 map = new OpenLayers.Map({
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
numZoomLevels:16,
zoom: 0,
maxResolution:156543.0339,
units:'m',
projection: "EPSG:900913",
displayProjection: new OpenLayers.Projection("EPSG:4326"),
div: "map_canvas",
controls: [
                new OpenLayers.Control.Navigation(),
                new OpenLayers.Control.PanZoomBar(),
                new OpenLayers.Control.MousePosition(),
                new OpenLayers.Control.LayerSwitcher()
        ],
});


var KML = new OpenLayers.Layer.Vector("KML", {
        strategies: [new OpenLayers.Strategy.Fixed()],
        protocol: new OpenLayers.Protocol.HTTP({
            url: "assets/text.kml",
            format: new OpenLayers.Format.KML({
                extractStyles: false, 
                extractAttributes: true

            })
        })
    });
  • Coordinate system in database: (one "Area") / Polygon.

    -179.999995473772 -89.9999977368861,-89.9999954737723 -89.9999977368861,4.52622771263123e- 06 -89.9999977368861,90.0000045262277 -89.9999977368861,179.999995473772 -89.9999977368861,179.999995473772 89.9999977368861,90.0000045262277 89.9999977368861,4.52622771263123e-06 89.9999977368861,-89.9999954737723 89.9999977368861,-179.999995473772 89.9999977368861,-179.999995473772 -89.9999977368861

Current error:

Uncaught Bad LineString point coordinates: -179.999995473772

share|improve this question
1  
why dont u use ST_GeomFromKML? –  Aragon Jan 2 '13 at 9:10
    
its probably the other way around.. From database to a KML file.. not from a KML into database.. –  Christer Jan 2 '13 at 9:18
    
The result from 1 column as you can see in my post is a "as_kml" result. –  Christer Jan 2 '13 at 9:27
1  
You might run into problems if your data exceeds 85.0511 to the North and South. North and South pole are not allowed in projection 900913. –  Andre Joost Jan 2 '13 at 10:18
    
Good to know @AndreJoost, But how can i transform these coordinates to that coordinate system ? –  Christer Jan 2 '13 at 10:27

2 Answers 2

To calculate the map center from a given pair of lat/lon coordinates, I use the following in Openlayers:

               var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
            map.setCenter (lonLat, zoom);

Maybe this function can help you with KML.

share|improve this answer
up vote 2 down vote accepted

i found a way to do it:

´format: new OpenLayers.Format.KML({
                extractStyles: true, 
                extractAttributes: true,
                maxDepth: 2,
                'internalProjection': options.projections.source, //EPSG:3785/900913
                'externalProjection': options.projections.display //EPSG:4326
            })´

Hope this helps anyone else :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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