Display coordinates on a map, not the right location is displayed.

Hello!

For my study i need to make a map of iceland and display location on it with coordinates. I have edit the code of this discussion: http://forum.processing.org/one/topic/using-a-world-map-in-processing.html

The location seems displays the location mirrored, i hope someone can look at the code. And more importend explain what the error/bug is:).

Hopefully someone can help me with this question.

Thank you very much.

map of iceland: https://www.dropbox.com/s/mmltfgzfu2ftc8a/island.png?dl=0

Code:

// Declaring a variable of type PImage

PImage backgroundMap;

float mapGeoLeft   =  -66.50;        // Longitude 66 degrees west
float mapGeoRight  =  -63.50;          // Longitude 63 degrees east
float mapGeoTop    =   24.20;            // Latitude 24 degrees north.
float mapGeoBottom =   13.80;       // Latitude 13 degrees south.

float mapScreenWidth,mapScreenHeight;  // Dimension of map in pixels.

void setup()
{
  size(1000,812);
  smooth();
  noLoop();
    // Make a new instance of a PImage by loading an image file
  backgroundMap   = loadImage("island.png");
  mapScreenWidth  = width;
  mapScreenHeight = height;
}

void draw()
{
  image(backgroundMap,0,0,mapScreenWidth,mapScreenHeight);

  fill(255,0,0);
  strokeWeight(0.5);

  PVector p = geoToPixel(new PVector(-64.08,21.56));  // reykjavik
  ellipse(p.x,p.y,20,20);


}

// Converts screen coordinates into geographical coordinates. 
// Useful for interpreting mouse position.
public PVector pixelToGeo(PVector screenLocation)
{
    return new PVector(mapGeoLeft + (mapGeoRight-mapGeoLeft)*(screenLocation.x)/mapScreenWidth,
                       mapGeoTop - (mapGeoTop-mapGeoBottom)*(screenLocation.y)/mapScreenHeight);
}

// Converts geographical coordinates into screen coordinates.
// Useful for drawing geographically referenced items on screen.
public PVector geoToPixel(PVector geoLocation)
{
    return new PVector(mapScreenWidth*(geoLocation.x-mapGeoLeft)/(mapGeoRight-mapGeoLeft),
                       mapScreenHeight - mapScreenHeight*(geoLocation.y-mapGeoBottom)/(mapGeoTop-mapGeoBottom));
}

Answers

  • How to post code

    when you post your code:

    • in the editor hit ctrl-t to auto format

    • copy it

    • paste it in the browser

    • leave 2 empty lines before it, 1 line after it

    • mark the code (without the 3 empty lines)

    • press C in the small command bar.

  • Thank you for the feedback Chrisir, i have edit the post.

  • Can somebody help me with this problem?

  • I can't really help to fix this code. But some thoughts:

    The way it is now, it seams inverted, are you getting all coordinates right?

    Have you minded the projection used for this specific map? You know, the earth is a sphere and all maps need a calculation to represent it as a plane. This does meters.

    Have you heard of unfolding maps? It's a library that makes map plotting really easy.

    Once I've done this for the 'Kavrayskiy' projection. Here the post with the code:

    http://forum.processing.org/one/topic/plotting-decimal-cordinates-to-kavrayskiy-map-projection.html

    HTH

  • edited September 2014

    I have the same hunch as _vk. The conversion methods from Jo Wood are for Equirectangular projection, but your Iceland map is in a different projection (easily recognizable due to the bended arctic circle line).

    You need to either select a different map of Iceland (in equi-rectangular projection for use of the conversion methods above, or Mercator for use in Unfolding), or you have to use a map library capable of converting screen coordinates to the one from your map's projection (then you still would need to figure out which one that is exactly).

Sign In or Register to comment.