Giter VIP home page Giter VIP logo

Comments (13)

rouault avatar rouault commented on June 15, 2024 2

fix in #6897

from mapserver.

geographika avatar geographika commented on June 15, 2024

@wicksell - maybe #6279 could have caused this. If you are able to roll back this change and test that would be helpful. Alternatively rather than recompiling could you try setting the extent of all your layers once you have switched projection to see if you get an image?

    map.setProjection("init=epsg:3006");
    map.setSize(256, 256);
    map.setExtent(642080, 7198656, 642112, 7198688);
    // TODO loop through all layers in the map and set the extent on these in the new projection

from mapserver.

jmckenna avatar jmckenna commented on June 15, 2024

(I'm not sure my comment here is useful, or if I am testing something different by accident) : I've run a few tests with PHP MapScript, on Windows with MS4W 5.0 : with MapServer 7.6.5 I don't have to re-declare the new mapObj instance, but with MapServer-git-main I must always re-declare, with something like $oMap = new mapObj(path); otherwise I get a blank image when trying the second reprojection. (setting layer extent does not affect the problem)

from mapserver.

jmckenna avatar jmckenna commented on June 15, 2024

Tomorrow I will add in a hint in the documentation, that the layer extent is actually in the coordinates of the layer source projection (this is not so clear I think, for the user, who might assume that the layer extent is in the 'new' (MAP) projection coordinates. Ok, sorry for my confusing comments, will wait for @wicksell response, ha.

from mapserver.

wicksell avatar wicksell commented on June 15, 2024

I have tested looping over all layers after setting the new projection. Setting the extent in the layers projection, as I understand is the correct way, has no effect. Setting it to the an extent in the map projection give error "msProjectRect(): Projection library error. All points failed to reproject. (message repeated 1 times)".

I have the same results as described above by @jmckenna, in 8.0.x i get a blank image if I don't reload the map with new mapObj(path);. The strange thing is that this only occur if the layer is in WGS84, however I have not tested all projections :), and not when the layer is in SWEREF99 TM.

I will try rolling back #6279 and see if that helps.

from mapserver.

wicksell avatar wicksell commented on June 15, 2024

I have now tried to roll back #6279 and unfortunately it had no effect.

from mapserver.

wicksell avatar wicksell commented on June 15, 2024

I have tested more to find a workaround and then come to slightly different conclusions than before. It is only possible to change the projection once, regardless of which projection the data is in. Then the map can be used with its initial projection or the first projection that it was changed to. Other projections can not be used until a new mapObj is created.

from mapserver.

geographika avatar geographika commented on June 15, 2024

@wicksell - I was able to recreate and came to the same conclusion. Whatever projection is first used can always be used but any other projections don't return data in the image. I can see why it is happening, but not the cause..

The shapes are reprojected here:

msProjectShapeEx(layer->reprojectorLayerToMap, shape);

I tested using a projection without a change and then using a different projection first. In both cases the reprojectorLayerToMap and shape seem identical when passed in to the function (same bounds, points etc.), and as far as I can tell the reprojector object looks the same:

    in: 0x000002081119dd10 {args=0x00000208144e4400 {0x00000208150f5380 "init=epsg:4326"} proj=0x0000020813921fa0 {...} ...}
    out: 0x0000020813c5b220 {args=0x0000020814480760 {0x00000208150f55a0 "init=epsg:3006"} proj=0x0000020814f02d40 {...} ...}
    pj: 0x00000208133401c0 {...}
    lineCuttingCase: LINE_CUTTING_UNKNOWN
    splitShape: {line=0x0000000000000000 <NULL> values=0x0000000000000000 {???} geometry=0x0000000000000000 ...}
    bFreePJ: 0

However the broken version does not correctly return the shape - its bounds are incorrect for the target projection:

Working shape before reprojection: bounds: {minx=17.997981199564393 miny=64.881029549666493 maxx=18.004429230036195 ...}
Working shape after reprojection:

    numlines: 1
    numvalues: 0
    bounds: {minx=17.997981199564393 miny=64.881029549666493 maxx=18.004429230036195 ...}

Broken shape before reprojection: bounds: {minx=17.997981199564393 miny=64.881029549666493 maxx=18.004429230036195 ...}
Broken shape after reprojection:

    numlines: 0
    numvalues: 0
    bounds: {minx=2003526.1024424192 miny=9577103.7174967937 maxx=2004243.8939111596 ...}

Then as numlines is 0 the function stops before drawing the feature at

if(shape->numlines == 0) {

In conclusion there is something different with the reprojections (a cached object? something different in the projectionContext?) - but I'm unable to find out what it is.

from mapserver.

wicksell avatar wicksell commented on June 15, 2024

Probably msProjectShapeLine return MS_FAILURE at

if( msProjectShapeLine( reprojector, shape, i ) == MS_FAILURE )

or msProjectLineEx return MS_FAILURE at
} else if( msProjectLineEx(reprojector, shape->line+i ) == MS_FAILURE ) {

resulting in line being deleted from the shape.

I think there should be a check if at msProjectShapeEx returns MS_FAILURE at

msProjectShapeEx(layer->reprojectorLayerToMap, shape);

so that these issues not just pass by unnoticed.

from mapserver.

geographika avatar geographika commented on June 15, 2024

@wicksell - no errors are thrown when reprojecting. It appears the feature is correctly reprojected to the first projection used, and therefore isn't rendered. The points are reprojected using the "cached"/first projection here:

c = proj_trans (reprojector->pj, PJ_FWD, c);

Even though the reprojector->pj looks to have the correct 2 projections:

in: 0x00000189beaef860 {args=0x00000189bea6ae70 {0x00000189bceb58e0 "init=epsg:4326"} proj=0x00000189beaf05a0 {...} ...}
    out: 0x00000189bcb5ad00 {args=0x00000189befd7060 {0x00000189bee6ed10 "init=epsg:3006"} proj=0x00000189bee77c30 {...} ...}

When setting the projection in MapScript the following function is called:

msFreeProjectionExceptContext(p);

I'm guessing something is cached in the projection context that causes this?
@rouault any ideas? Recreating a new projection context is presumably costly, but could maybe be added to the MapScript setProjection call only?

from mapserver.

rouault avatar rouault commented on June 15, 2024

any ideas?

I'm on it

from mapserver.

geographika avatar geographika commented on June 15, 2024

Sorry to drag you in to the ticket..I need to sort out some PROJ debug builds so I can look into these myself..
Here was my test script in Python based on the example Mapfile and data in the zip attached to the ticket.

import mapscript
import os

pth = r"D:\Temp\test-change-projection\wgs84"
map = mapscript.mapObj(os.path.join(pth, "test.map"))

map.setProjection("init=epsg:3857")
map.setSize(256, 256)
map.setExtent(2003499.4,9577066.7,2003987.7,9577395.3)

image1 = map.draw()
image1.save(os.path.join(pth, "myimage.png"), map)

map.setProjection("init=epsg:3006")
map.setSize(256, 256)
map.setExtent(642080, 7198656, 642112, 7198688)
image2 = map.draw()
image2.save(os.path.join(pth, "myimage2.png"), map)

from mapserver.

wicksell avatar wicksell commented on June 15, 2024

Big thanks for resolving this issue so quickly! I have tested the pull request with 8.0.1 and it works great :)

from mapserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.