GIF Raster Image Process Problem {Scanned}

Siki Zoltan siki at AGT.BME.HU
Tue May 10 17:02:22 EDT 2005


Dear Akio,

I do not know any free tool to do the task direcly. Recently I have faced
to the same trouble. The name of the raster files contained a row and
a column number. I wrote a simple program to do the task, I attache the c source.
An other possible solution to draw the border of the images in a
polygon shape file, add the name of the corresponding raster file as an
attribute to the polygon and write a "simple program" using shapelib ...

I hope it helps you

Zoltan

On Tue, 10 May 2005, Akio Neuchi wrote:

> Dear Zoltan,
>
> Thanks for your tips.
> Now I am facing another problem.
> Tile indexing various gif images -- around 800 per district ( in Japan there
> are around 10 districts in sum),
> to a single shp using GDALtindex.
> Though I am thinking for writing a program to generate the same number of
> world files,
> it would be very helpful if there is a free program to do the job.
> Do you have any idea?
> Thanks again,
>
> Akio
>
> -----Original Message-----
> From: Siki Zoltan [mailto:siki at agt.bme.hu]
> Sent: Friday, May 06, 2005 8:27 PM
> To: Akio Neuchi
> Cc: MAPSERVER-USERS at LISTS.UMN.EDU
> Subject: RE: [UMN_MAPSERVER-USERS] GIF Raster Image Process Problem
> {Scanned}
>
>
> Dear Akio,
>
> The formula looks like:
> X = Ax + By + C and Y = Dx + Ey + F (Affine transformation)
> The order of the parameters in the world file is:
> A
> D
> B
> E
> C
> F
>
> The process to find out the values of the parameters is called
> georeferencing. There are a loft of programs what can solve the task
> specifying point on the raster and giving the real co-ordinates for them.
> Unfortunatelly I use commercial software for this purpose, but I think
> GRASS can do it.
> Usually more then the minimal 3 points are used with a least squares
> estimation.
>
> I hope it helps you
>
> Zoltan
>
> On Fri, 6 May 2005, Akio Neuchi wrote:
>
> > Dear Zoltan�
> >
> > Sorry for my late reply.
> > We were in long holidays here in Japan.
> > Thank you for your recommendations.
> > In fact, by adjusting World file, the Raster/Vector Images finally so-so
> well superimposed,
> > except the coordinates of these images are a bit dislocated, depend on the
> 1st and 4th pixel values on the World file.
> > Though I am adjusting manually those numbers, what is the right formula to
> get the X and Y pixel dimensions?
> > Thanks again for your help.
> >
> > Akio
> >
> > <World file>
> > 0.000038
> > 0.0000000000
> > 0.0000000000
> > -0.000038
> > 139.738114
> > 35.691990000000004
> >
> > MAP #file
> > NAME rastest
> > STATUS ON
> > SIZE 600 700
> > EXTENT 139.5 35.5 140 36
> > UNITS dd
> > SHAPEPATH "data"
> > FONTSET "./fonts/fonts.lst"
> > IMAGECOLOR 225 240 200
> > IMAGETYPE GIF
> >
> > # Projection definition, set-upped by PROJ.4 parameters
> > PROJECTION
> > #   "init=epsg:26915"
> >     "proj=latlong"
> > END
> >
> > # Web interface definition (including WMS enabling metadata)
> > WEB
> >     EMPTY "/gistest/empty.html"
> >     HEADER decide_route_header.html
> >     TEMPLATE decide_route.html
> >     FOOTER decide_route_footer.html
> >     MINSCALE 0
> >     MAXSCALE 300000000
> >     IMAGEPATH
> /var/opt/SUNWappserver7/domains/domain1/server1/docroot/gistest/tmp
> >     IMAGEURL /gistest/tmp
> >     LOG
> /var/opt/SUNWappserver7/domains/domain1/server1/docroot/gistest/rastest.log
> > #   TEMPLATE "decide_route.html"
> >     METADATA
> >             WMS_TITLE "MapDisplay Demo"
> >             WMS_ABSTRACT "Created by AN"
> >             WMS_ACCESSCONSTRAINTS none
> >     END
> > END
> >
> > QUERYMAP
> >     SIZE 200 200
> >     STATUS ON
> >     STYLE HILITE
> >     COLOR 255 0 0
> > END
> >
> > OUTPUTFORMAT
> >      NAME gif
> >      MIMETYPE "image/gif"
> >      DRIVER "GD/GIF"
> >      EXTENSION "gif"
> > #    IMAGEMODE RGB
> > IMAGEMODE PC256
> >      TRANSPARENT FALSE
> > #    TRANSPARENT TRUE
> > #    FORMATOPTION "INTERLACE=OFF"
> > END
> >
> > ### RASTER Layer
> > LAYER
> >     NAME "RAS365313"
> >     GROUP "B_RASTER"
> >     TYPE RASTER
> >     DATA "MS12000DEF365313.gif"
> > #   STATUS ON
> >     STATUS DEFAULT
> >         TRANSPARENCY 100
> > #   OFFSITE 125 135 148
> >     PROJECTION
> >             "proj=latlong"
> > #           "init=epsg:26915"
> >     END
> >     PROCESSING "LOAD_WHOLE_IMAGE=TRUE"
> > END
> >
> > # here starts Vector Layers
> > # background - Parks
> > LAYER
> >     NAME "BARA_PARK_AREA"
> >     GROUP "BARA_PARK"
> >     TILEINDEX "v_bak_ara_park"
> >     STATUS ON
> >     MAXSCALE 200000
> >     TYPE POLYGON
> >     PROJECTION
> > #           "init=epsg:26915"
> >             "proj=latlong"
> >     END
> >     CLASS
> >             BACKGROUNDCOLOR 0 220 0
> >             COLOR 150 200 100
> > #           COLOR 154 205 50
> >     END
> > END
> >
> > # background - Sea surface
> > LAYER
> >     NAME "BARA_SEA"
> >     TILEINDEX "v_bak_ara_sea"
> >     STATUS default
> >     TYPE POLYGON
> >     PROJECTION
> > #           "init=epsg:26915"
> >             "proj=latlong"
> >     END
> >     CLASS
> >             BACKGROUNDCOLOR 0 255 255
> >             COLOR 100 149 237
> >     END
> > END
> >
> > # background - Rivers
> > LAYER
> >     NAME "BLIN_RIVER"
> >     TILEINDEX "v_bak_lin_river"
> >     STATUS default
> >     MAXSCALE 200000
> >     TYPE LINE
> >     PROJECTION
> > #           "init=epsg:26915"
> >             "proj=latlong"
> >     END
> >     CLASS
> >             BACKGROUNDCOLOR 0 255 255
> >             COLOR 100 149 237
> >     END
> > END
> > END # Map File
> >
> > -----Original Message-----
> > From: Siki Zoltan [mailto:siki at agt.bme.hu]
> > Sent: Friday, April 29, 2005 5:31 PM
> > To: Akio Neuchi
> > Cc: MAPSERVER-USERS at LISTS.UMN.EDU
> > Subject: Re: [UMN_MAPSERVER-USERS] GIF Raster Image Process Problem
> {Scanned}
> >
> >
> > Dear Akio,
> >
> > You should define EXTENT, UNITS and SHAPEPATH at separate lines.
> > Do you have world file to your image? Check the extents.
> > Try STATUS DEFAULT.
> >
> > Bye Zoltan
> >
> >
> >
>
-------------- next part --------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

char *strup (char *str) {
	char *p = str;
	while (*p) *p++ = (char) toupper(*p);
	return str;
}

int main (int argc, char *argv[]) {
//	create world files
	int i, row, col;
	long x, y;
	FILE *fp;
	char name[100], oname[10], ext[4];
	char *p, *q;
	double width, height;

	if (argc < 4) {
		fprintf (stderr, "usage: tfw width height files\n");
		fprintf (stderr, " width - image width in pixels\n");
		fprintf (stderr, " height - image height in pixels\n");
		fprintf (stderr, " files  - name/pattern of one or more files\n");
		return -1;
	}
	/* sizes */
	width = 750.0 / atof (argv[1]);		// replace the real width 750
	height = 500.0 / atof (argv[2]);	// replace the real height 500
	for (i = 3; i < argc; i++) {
		strcpy (name, argv[i]);
		fprintf (stderr, "%s\n", name);
		p = &(name[strlen(name)-4]);
		strup (p);
		if (strcmp (p, ".TIF") && strcmp (p, ".JPG") && strcmp (p, ".GIF") &&
				strcmp (p, ".PCX") && strcmp (p, ".BMP") && strcmp (p, ".TGA") &&
				strcmp (p, ".BIL")) {
			fprintf (stderr, "unsupported raster format: %s\n", name);
			continue;
		} else {
			q = &(name[strlen(name)-8]);
			strncpy(oname, q, 4);
			oname[4] = '\0';
			if (strcmp (p, ".TIF") == 0) strcat (oname, ".tfw");
			else if (strcmp (p, ".JPG") == 0) strcat (oname, ".jgw");
			else if (strcmp (p, ".GIF") == 0) strcat (oname, ".gfw");
			else if (strcmp (p, ".PCX") == 0) strcat (oname, ".pxw");
			else if (strcmp (p, ".BMP") == 0) strcat (oname, ".bpw");
			else if (strcmp (p, ".BIL") == 0) strcat (oname, ".blw");
			else exit (-1);
			fp = fopen (oname, "wt");
			// calculating coordinates from row and column number
			row = (q[0] - '0') *10 + (q[1] - '0') - 44;
			col = (q[2] - '0') *10 + (q[3] - '0') - 24;
			x = 642750L + (long) col * 750L;	// change the constants!
			y =	233500L - (long) row * 500L;
			fprintf (fp, "%.8lf\n", width);
			fprintf (fp, "0.0\n");
			fprintf (fp, "0.0\n");
			fprintf (fp, "%.8lf\n", height);
			fprintf (fp, "%ld\n", x);
			fprintf (fp, "%ld\n", y-500L);
			fclose (fp);
		}
	}
	return 0;
}


More information about the mapserver-users mailing list