Rasters, TileIndex and Shapefiles - Oh My! Really Confused

Ed McNierney ed at TOPOZONE.COM
Thu Sep 27 14:37:01 EDT 2007


Chris -

 

I think you need to spend a few moments meditating on the fact that the
world file DESCRIBES the image it's associated with.  It does not DEFINE
it.  If you change the numbers in your UTM-projection world file to
lat/lon coordinates, your application will break.  You haven't changed
the fact that your image is still in the UTM projection!  If your image
is UTM, your world file must be UTM.  A world file like your second
example is saying "here's a description of my image file, which is in a
lat/lon 'projection'.  Each pixel is one degree wide by one degree high
(!) and the upper left corner is at longitude -88 and latitude 40".
That is not at all a correct description of your image file.

 

MapServer knows all about map projection, and you can define several
layers in a map each in a different projection.  Your output map image
may be in yet another projection.  There's nothing wrong with creating a
map file that defines one layer as your photo TILEINDEX in UTM
projection, another point layer in lat/lon coordinates, and an output
image being displayed and requested in lat/lon coordinates (or in UTM,
or in something else entirely).

 

Get your LAYER definition for your TILEINDEX photo layer (or single
image layer) in UTM projection working properly.  Do nothing else.  Once
you have a map being displayed correctly you can (a) set the output
image projection to lat/lon if you insist, and/or (b) add data points in
lat/lon coordinates.

 

-          Ed

 

P.S. If you look at this URL:

 

http://www.topozone.com/map.asp?lat=40.10802&lon=-88.22711&datum=nad83

 

you'll see that the URL requests a point in lat/lon coordinates and that
point is displayed as a red market symbol in the middle of a map image
which is in UTM projection, with the corresponding UTM coordinates
displayed above the map.

 

Ed McNierney

TopoZone.com

 

________________________________

From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On
Behalf Of Christopher Harris
Sent: Thursday, September 27, 2007 10:15 AM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: Re: [UMN_MAPSERVER-USERS] Rasters, TileIndex and Shapefiles -
Oh My! Really Confused

 


K.  Thought I put the mapserver-users email address in the reply.  It
should be in there this time.  

Hmmmm - to clarify how I got these images:
1.) http://www.uiuc.edu/
2.) There are some white links in the top left corner.  Click on Maps.
3.) Now a big map should be displayed.  This isn't the one.  Click
anywhere on that big map.
4.) The tile where you clicked will be displayed, but that's not how I
get the tiles.  If you notice there's no way to tell how long a tile is
or how to line them up.  Ok.  There's a little map to the right of that
tile being displayed that says "click to jump" underneath it.
5.) Click in that box anywhere and it will show tiles in the big box to
the left that are evenly spaced apart (except the far right and very
bottom).  If you click on a few places within the small box, you see how
the white rectangle with red borders inside the small box moves at the
same interval for every tile.  So, from there I right-click on the big
tile image being displayed and select Save Image.
6.) This is where I got my pics from.  I also assembled them last night
anyway for amusement, and they fit perfectly.  Just the very bottom row
and the far right column overlap.  But, I know now that the overall
mosiac's width is 2602 and the height is 2800.


Ideally, I would like the world file to be in lat/lon (that's funny
about people on the web thinking the Earth is flat - brings an old Bugs
Bunny cartoon to mind), being as I have to convert a lat/lon point
someone sends me to UTM as of right now.  I would love to not have to
convert - just less code is always better to me.

Yeah.  I know it's in Zone 16.  I looked that up a while back on a UTM
grid I found online.

Ok.  So, my current world file (in UTM):
1
0.0000000000
0.0000000000
-1
393898.00
4441379.00

So..... for lat/lon I could say...........:
1
0.0000000000
0.0000000000
-1
-88.248281
40.117268

(This would put the Top Left coordinate in an area called West Side
Park.  I took that assembled map pic and then grabbed a screen shot of
the current window I was in and made that into an image and aligned them
via layering and opacity levels in The GIMP (Like Photoshop but in
Ubuntu Linux)).

I'll double check the math, but I don't know if what I described earlier
with all the steps could be screwing things up.

And lastly, in the world file, 1 would represent 1 decimal degree/pixel
or 1 meter/pixel in the X direction (depending on UTM or lat/lon)?

I checked out Topozone.  It looks like it has a ton of features.  I'll
play around with it some more.  

Thanks!!!!

 - Chris

________________________________

Subject: RE: [UMN_MAPSERVER-USERS] Rasters, TileIndex and Shapefiles -
Oh My! Really Confused
Date: Wed, 26 Sep 2007 18:25:52 -0400
From: ed at topozone.com
To: docterrobert at msn.com; MAPSERVER-USERS at LISTS.UMN.EDU

Chris -

 

(I added the list back to the reply line - please always reply to the
whole list - thanks)

 

A world file is in the units of the image's projection, not the other
way around.  Having a world file does not mean the image is in UTM
projection.  The UTM projection is a popular one, but it's certainly not
the only one.  For a map in Illinois UTM is certainly a possibility, but
an Illinois State Plane Coordinate System projection is also a
possibility - especially if the original imagery came from the State of
Illinois.  And geographic lat/lon coordinates are also a possibility due
to the increasing number of people in the world who seem to think the
Earth is flat (at least on the Web).

 

I don't know which campus you're using, but if you're at UIUC then the
UTM coordinates will be in UTM Zone 16 with values of around 395000 (X
or Easting)  4440000 (Y or Northing).  If your numbers don't look like
those, they're not UTM.

 

Oh, sorry - I started answering before reading all the questions, and
you later seem to confirm that your coordinates are indeed UTM.  But you
got the formulas backwards, and X should be positive while Y should be
negative- not the other way around.  And the measurements in your world
file are indeed in meters, but that's because those are the native units
of the UTM projection being used.  There's nothing that requires them to
be in meters; many US state plane coordinate systems use units of feet,
and those would appear in the world file, too.

 

Now it is highly unlikely that your pixel resolution is different in
each dimension.  You could average those two numbers, or double-check
your coordinate values (you didn't say what source you used to get
them).  If you got this image from a GIS source, I would say that if you
think the dimensions are different you're wrong, but who knows what the
University did to munge the image into a pretty picture.  So maybe the
dimensions ARE different; that's not impossible, just odd.  I still
would double-check your measurements and math, but if you get the same
answer that's OK.

 

Once you do that you just have to crank out those world files!

 

-          Ed

 

Ed McNierney

TopoZone.com

 

________________________________

From: Christopher Harris [mailto:docterrobert at msn.com] 
Sent: Wednesday, September 26, 2007 1:13 PM
To: Ed McNierney
Subject: RE: [UMN_MAPSERVER-USERS] Rasters, TileIndex and Shapefiles -
Oh My! Really Confused

 

Wow.  Thanks Ed.  You went to a lot of trouble.  Most of this stuff
you've explained I have a handle on.  I wikipedia'd how to make a world
file when I did that previous app.  And yes, it's the same app with the
image that's in UTM projection.  I actually have one last question about
that, but I'll do a separate post for that.  This is a modification of
that app.  See, I've been using this "Parking Lot" map for the
University of Illinois, because I couldn't find a better looking one.
Well, yesterday, I noticed that you could go their full campus map and
right click on each individual tile and save it as a .gif.  I had tried
this before but was apparently clicking on certain, wrong areas of each
tile every time where I guess the javascript was blocking me.  The
javascript that they use displays info on certain buildings when you
click on them.  If you happen to right-click on or around a building and
try to save, you can't.  You have to click somewhere else on the tile
that's on or around a building.  Anywho - my boss now wants me to take
what I've done with that one pic of  the "Parking Lot" and now apply it
to a big tiled image of the entire campus (enter the tiles I've saved).
That's the back story as to what's going on.

I have 3 questions now.

#1 You asked if the image is in UTM.  I'm basing the image projection on
the world file.  I remember you (or maybe this one other guy on this
list serv) telling me before that you can't distinguish what projection
a world file is in - that that's one of the cons to world files.  Every
example I've ever seen after typing in "World File" in Google shows a
world file that is in meters and says that it's using UTM projection.
That's still the case right?

Oh, the lat/lon has to do with me reprojecting.  See, someone passes me
a lat/lon coordinate (a center point).  I then take that, and convert it
to UTM, because the map's projection is in UTM due to the world file
being in UTM.

Thanks for your time and patience by the way.  You've been a huge help.

#2 The one thing I'm hazy on in regard to the world file is: 
the 1st and 4th line - pixel size in the x-direction and y-direction in
map units/pixel

I understand why x is positive and y is almost always negative.  But,
does that mean, for example, 
if I type 2 for the 1st line and -2 for the fourth line, then there will
be 2 meters per pixel going both directions?  For that I could never
find an example of what they meant.  I just assumed that.  I usually
work best with seeing an example, and one was never provided on any of
the pages I visited.

#3 "The X pixel dimension will be (maxx - minx) / xpixels, and the Y
will be (miny - maxy) / ypixels.  You should find that the X number is
-1 times the Y number."

Is pixel dimension related to question #2?  For instance (in meters):

TL - 393898 4441379 BR - 396253 4438945

maxx=393898, maxy=4441379
minx=396253, miny=4438945

DeltaX=-2355, DeltaY=2434

Say the mosaic's dimensions in pixels are.........: X=1500, Y=2000

X pixel dimension = -2355/1500 = -1.57 meters/pixel
Y pixel dimension = 2434/2000 = 1.217 meters/pixel

That right?

 - Chris

________________________________

Subject: RE: [UMN_MAPSERVER-USERS] Rasters, TileIndex and Shapefiles -
Oh My! Really Confused
Date: Wed, 26 Sep 2007 14:45:54 -0400
From: ed at topozone.com
To: docterrobert at MSN.COM; MAPSERVER-USERS at LISTS.UMN.EDU

Chris -

 

OK - it's not as bad as all that - don't fire up Photoshop yet.  If you
have a set of tiles which together create a seamless large image, and
those tiles are of a regular size and shape, don't bother pasting them
together.

 

Each world file has six numbers in it, two of which will be 0.  For each
image tile you need a world file that contains the X/Y coordinates of
the upper left pixel of the image (two numbers), and the dimension
(size) of each pixel in X (one number) and Y (one number) units.  In the
vast majority of cases the last two numbers will be identical except for
sign (the Y value is normally a negative number since Y values decrease
as you go from the top to the bottom of the image).

 

If your images make a rectangle when pasted together, just treat them as
one.  Find the X/Y coordinates of the upper left corner of the entire
image area, and the X/Y coordinates of the lower right corner of the
entire image area.  Find the size of the entire mosaiced rectangle in X
and Y pixels.  The X pixel dimension will be (maxx - minx) / xpixels,
and the Y will be (miny - maxy) / ypixels.  You should find that the X
number is -1 times the Y number.

 

For all your world files, these two X and Y extent values (the first and
fourth lines) will be constants.  The last two lines are the upper left
X and Y coordinates of each tile.  Your tiles will all have the same Y
value across each row, and the same X value down each column.  You know
what the upper-left corner of the upper-left tile is, because you
measured it.  You know the number of X pixels in each tile and the
number of Y pixels in each tile, and you now know the size in X and Y
units of each pixel, so you know the extent of each image tile in X and
Y units, so you can calculate the upper-left corner coordinate of the
image to the right and the image below.  Repeat until complete.

 

All your measurements need to be done in the units of the image's
coordinate system.  Is this the image you were asking about earlier
that's in UTM projection?  If so, you need UTM coordinates, NOT lat/lon.
I wouldn't recommend Google Earth as a very accurate way to do that, but
if it's close enough for you and easy that's OK.  If you can easily find
the corners of your image area on a topo map you can do it on TopoZone
and get UTM coordinates accurate to within a few meters just by clicking
on the spots that match the corner points of your image.

 

If there isn't an obvious landmark at the corner, you can pick a
prominent location NEAR the corner and just measure the number of pixels
away from the corner it is.  It's just a bit more bookkeeping but does
the same thing.

 

-          Ed

 

Ed McNierney

TopoZone.com

 

________________________________

From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On
Behalf Of Christopher Harris
Sent: Wednesday, September 26, 2007 11:15 AM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: Re: [UMN_MAPSERVER-USERS] Rasters, TileIndex and Shapefiles -
Oh My! Really Confused

 

Thanks again, Ed.  I need to clear up some things that I guess I didn't
make clear.

I know that a world file provides georeferencing.  I meant to say that I
had a .gif that had no georeferencing info associated with it, and then
added one.  From there I got my initial app to work (displaying the big
map).

One thing I omitted was that the little .gifs (tiles), when assembled,
make up a different big map pic then the one where mentioned :

"it uses one .gif (the big map pic), attaches the big map to the globe
via a world file.  That big map .gif had no georeferencing info attached
to it."

Before I had a pic of a large section of a college campus.  Now I have a
pic of the entire campus, but in little tiles.

I know Mapserver makes maps and not pics too.  I probably just worded
something wrong.

"So - what do you know about these images?  Do you really have a world
file that correctly describes your big GIF image?  Do you know exactly
how the little images were created from the big image?  If so, you
should be able to figure out how to generate world files for each
individual image.  If not, you'll need to get that information for your
big image."

Yes, I have a world file, but it's for the pic that shows a large
section of the campus - not for the big pic that is the sum of the
little pics.


Ok, so then I have to have a world file for every little tile, but
before that I need to correctly set up the world file for the big pic,
which I guess I'll need to assemble in Photoshop.  Does that sound
right?  I can do it, it's just a bit tedious lining up the tiles and
such.  Also, how do you correctly align a pic of some map on the globe.
I've been using Google Maps to do it.  I'll sit there and study where
the pic's corners should approximately be, then get the lat/lon from
that (clicking directions to or from will yield the lat/lons).

Thank you.

 - Chris  

________________________________

Subject: RE: [UMN_MAPSERVER-USERS] Rasters, TileIndex and Shapefiles -
Oh My! Really Confused
Date: Wed, 26 Sep 2007 13:36:42 -0400
From: ed at topozone.com
To: docterrobert at MSN.COM; MAPSERVER-USERS at LISTS.UMN.EDU

Chris -

 

Let me suggest you try to get unconfused just one step at a time!

 

"it uses one .gif (the big map pic), attaches the big map to the globe
via a world file.  That big map .gif had no georeferencing info attached
to it."

 

That's a bit of a contradiction.  A world file is one way of providing
georeferencing.  If you've got an image "attached" to the Earth via a
world file, you've georeferenced it.

 

MapServer makes maps, not pictures.  One of the chief differences is
that a map has geographic location information associated with it.  When
you ask MapServer to generate a map for you, you need to tell it the
location of the map you want in some coordinate system.  In order for
MapServer to know which of your GIF images to use in making the output
map, it needs to know the geographic location of each of those images.
Otherwise it couldn't figure out which ones to use.

 

A TILEINDEX is step two in the process.  Once you have a set of more
than 1 properly georeferenced images that you'd like to use like a
single logical image, you can create a TILEINDEX to do that.  But you
have to completely and correctly make it through step one first.  Once
you get the individual images properly georeferenced, gdaltindex will
just work.

 

So - what do you know about these images?  Do you really have a world
file that correctly describes your big GIF image?  Do you know exactly
how the little images were created from the big image?  If so, you
should be able to figure out how to generate world files for each
individual image.  If not, you'll need to get that information for your
big image.

 

If you do have that world file and know how the tiles were created, let
us know (you can post the world file in your reply - it's just six lines
of text).

 

-          Ed

 

Ed McNierney

TopoZone.com

 

 

________________________________

From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On
Behalf Of Christopher Harris
Sent: Wednesday, September 26, 2007 10:02 AM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: [UMN_MAPSERVER-USERS] Rasters, TileIndex and Shapefiles - Oh
My! Really Confused

 

Hi.  I have a map that is broken up into a bunch of .gif tiles.  I want
to display them on a layer in Mapserver.  I have working version of what
I want to accomplish, but it uses one .gif (the big map pic), attaches
the big map to the globe via a world file.  That big map .gif had no
georeferencing info attached to it.

These .gifs have no georeferencing information included or attached as
well.

I read Section 4 (and Section 9 too) on the mapserver site page:
http://mapserver.gis.umn.edu/docs/howto/raster_data



More information about the mapserver-users mailing list