5

We're running MapServer with a map that has just one layer, political boundaries from a SHP file. This layer is using a basic EPSG:4326 projection, and the map itself is using EPSG:3857. The resulting images generated by MapServer CGI queries have horizontal lines at certain latitudes:

enter image description here

Beyond this problem, the map is okay and lines up perfectly with the Open Street Map in OpenLayers. The MAPFILE we're using:

MAP
 WEB
 METADATA
 "wms_title" "Map Server"
 "wms_enable_request" "*"
 "wms_srs" "EPSG:3857"
 END
 END
 PROJECTION
 "init=epsg:3857"
 END
 IMAGETYPE PNG
 EXTENT -20037508.34 -20037508.34 20037508.34 20037508.34
 SIZE 400 300
 SHAPEPATH "../data"
 IMAGECOLOR 71 245 242
 LAYER # States polygon layer begins here
 NAME Borders
 DATA ne_10m_admin_1_states_provinces_shp
 STATUS OFF
 TYPE POLYGON
 PROJECTION
 "init=epsg:4326"
 END
 CLASS
 NAME "Borders"
 STYLE
 COLOR 43 156 51
 OUTLINECOLOR 32 32 32
 END
 END
 END # States polygon layer ends here
END 

I've verified that the proj.4 EPSG file has the proper definition of EPSG:3857, and don't understand what's happening. Any insight would be greatly appreciated.

djq
16.4k31 gold badges114 silver badges184 bronze badges
asked Dec 12, 2012 at 19:23

3 Answers 3

7

Your question implies that the problem doesn't occur when the data isn't projected. Is this the case?

It looks like the issue is with features that cross the -180 / +180 meridian. The problem arises when the GIS assumes that the west boundary of the polygon has a lower X ordinate than the east boundary, but in these cases this is reversed.

The problem isn't specific to MapServer and I expect you would see the same issue in any GIS software.

One way to address this sticky problem is to split these polygons over the meridian, so that the east side of the feature displays on the west of the map and the west side of the polygon is on the east side of the map.

answered Dec 13, 2012 at 0:57
1
  • 1
    Yes, that's right. The layer looks fine at its normal 4326 projection. Viewing the file in TatukGIS at certain projections, such as EPSG:3349, results in similar problems. So I think you guys are right about the shapefile containing some bad polygons. Interestingly, the problem doesn't happen when viewing the file at EPSG:3857. Commented Dec 13, 2012 at 16:25
3

Check whether your shapefiles are valid and contain no unclosed polygons. Apart from that it is better for your performance to reproject your shapefile first.

This can be done with eg ogr2ogr: ogr2ogr -s_srs EPSG:4326 -t_srs EPSG:3857 outfile.shp infile.shp

answered Dec 12, 2012 at 19:42
3
  • Wow, thanks. I used TatukGIS to view the SHP file and was able to track down one of the errant polygons. Adding a filter for it to the mapfile got rid of the line through Australia! The other polygons are harder to find. Is there a GDAL tool or debugging feature that would help? Commented Dec 12, 2012 at 22:30
  • 1
    Try reprojecting the shapefile, it may already solve your problem by closing all polygons when they are written again. If you want to keep the file in 4326 you just replace the -t_srs, but keep in mind that reprojecting layers on the fly is not good for performance. Commented Dec 13, 2012 at 8:22
  • Thanks. When I tried reprojecting the shapefile liked you suggested yesterday, the problem remained. I'll experiment with it some more today. Commented Dec 13, 2012 at 16:14
1

you may use the -wrapdateline option, together with a temp format (-f), say KML. It works fine.

answered Jul 29, 2013 at 10:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.