1

I am trying to a get polygon layer from CSV file. I chose to do it via rasterization and polygonization in QGIS, however, GeoServer has problems correctly rendering some polygons.

This is how the layer looks in QGIS (how it should look like):

enter image description here

And here is how the layer looks displayed from GeoServer (using OpenLayers):

enter image description here

You can see that at some point it is weirdly distorted, maybe kind of inverted. I read the Q/A GeoServer renders shape incorrectly both on Overflow and here at GIS. However, I am still lost. SRS of the layers should be set correctly as I have a lot of similar layers and its happens just for about 10% of them. If it is an issue of

caused by how different products create polygons. (...) From the GeoServer documentation it requires that polygons have the same first and last coordinate. I would recommend that you edit the polygons in the shapefile to accomplish this.

as suggested by Darkcylde. How can I fix it? What is more important, how can I avoid it, since I am in total control of layers production and it happens for about 10 % of them?

I found out that when I rasteryze the CSV file with too high resolution causing the layers "granulation" the problem vanishes (but the picture is useless):

enter image description here

Here are the files which I use to create the layer. I used the modelNo of value 4.

And here is the Python code used in QGIS:

from qgis.core import *
from qgis.gui import *
from qgis.utils import *
from time import sleep
from PyQt4.QtCore import *
from PyQt4.QtGui import QImage, QColor, QPainter

# change the import
import processing

class Loader:
    def __init__(self,iface):
       """Initialize using the qgis.utils.iface 
       object passed from the console.
       """
       self.iface = iface

    def create_models(self):
        print "inside a function"
        m = 11
        h = 16
        f = 4
        ss = "%02dm%02dh%dflx" % (m,h,f)

        uri = "file:///d:/GISdata/THRASH/ModGrids/MODgrid%s.dat?delimiter=%s&xField=%s&yField=%s&crs=epsg:4326" % (ss,",", "long", "lat")
        vlayer = QgsVectorLayer(uri, "MODgrid", "delimitedtext")

        writename = "d:/GISdata/THRASH/Temp/ModGridm%s.shp" % (ss)
        write = QgsVectorFileWriter.writeAsVectorFormat(vlayer,writename,"WGS84", None, "ESRI Shapefile")
        sleep(3)
        shLayer = QgsVectorLayer(writename,"PoinData", "ogr")

        raststore1 = "d:/GISdata/THRASH/Temp/testResh1.tif"
        processing.runalg("gdalogr:rasterize",shLayer,"modelNo",0,360,340,raststore1)

        NTCMname1 = "d:/GISdata/THRASH/Temp/1NTCM%s.shp" % (ss)
        processing.runalg("gdalogr:polygonize",raststore1,"DN",NTCMname1)
        player1 = QgsVectorLayer(NTCMname1, "NTCM", "ogr")
        ids = [f.id() for f in player1.getFeatures(QgsFeatureRequest().setFilterExpression(u'"DN"!=4'))]
        player1.dataProvider().deleteFeatures(ids)
2
  • You data crosses the -/+180 degree line so it it wrapping itself across the projection, make your data 179.5 degrees east/west it should solve the issue.
    – Mapperz
    Commented Nov 10, 2014 at 15:14
  • @Mapperz good point, unfortunately that did not solve the problem: (
    – MasterPJ
    Commented Nov 10, 2014 at 16:00

0

Your Answer

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