[mapserver-users] Announcing 3.6.3 [for Java]

Andrew Collins andrewrcollins at yahoo.com
Tue Oct 22 17:22:24 EDT 2002


Included below are the three files necessary to create an
implementation of MapScript for Java (on Windows, without
any extra library support--a barebones compilation) with
the most recent version of MapServer (3.6.3).

I used MinGW, MSYS, GnuWin32 and Swig 1.3.15.

  MinGW: Minimalist GNU For Windows
  http://www.mingw.org/

  MSYS
  http://www.mingw.org/msys.shtml

  GnuWin32
  http://gnuwin32.sourceforge.net/

  Swig
  http://www.swig.org/

The required libraries must be downloaded and unzipped in
the main MapServer distribution directory. You may download
pre-compiled versions from the GnuWin32 project pages:

  freetype-2.1.2-1-lib.zip
  freetype-2.1.2-bin.zip
  gdlib-1.8.4-1-bin.zip
  gdlib-1.8.4-lib.zip
  libjpeg-6b-bin.zip
  libjpeg-6b-lib.zip
  libpng-1.2.4-1-bin.zip
  libpng-1.2.4-1-lib.zip
  libttf-1.4-bin.zip
  libttf-1.4-lib.zip
  regex-0.12-bin.zip
  regex-0.12-lib.zip
  xpm-3.4k-1-bin.zip
  xpm-3.4k-1-lib.zip
  zlib-1.1.4-bin.zip
  zlib-1.1.4-lib.zip

The included files go in the mapscript/java directory.

Could these three files be added to the distribution?

I am currently working on a Java-style facade for the
implementation classes generated here.

== Makefile
== mapscript.i
== MapScriptTest.java

== Makefile

#/* File : Makefile */

#
# SWIG
#
SWIG=/e/win32app/SWIG-1.3.15/swig

#
# Java
#
JAVAC=/e/win32app/j2sdk1.4.1/bin/javac
JAVA=/e/win32app/j2sdk1.4.1/bin/java
JAR=/e/win32app/j2sdk1.4.1/bin/jar
JAVA_INCLUDE=-I/e/win32app/j2sdk1.4.1/include
-I/e/win32app/j2sdk1.4.1/include/win32

#
# CC
#
CC=gcc

#
#
#
CCFLAGS=-g -O2 -Wall -Wstrict-prototypes
MAPSCRIPT_FLAGS=-DIGNORE_MISSING_DATA -DUSE_JPEG -DUSE_GD_TTF -DUSE_GD_PNG
-DUSE_GD_JPEG -DUSE_GD_WBMP -DGD_HAS_GDIMAGEGIFPTR
INCLUDES=-I../../ -I../../include/ $(JAVA_INCLUDE)
LDFLAGS=-L../.. -L../../lib -ljpeg_static -ljpeg -ljpeg_static -lttf -lpng -lz
-lfreetype -lm -lregex

#
#
#
all: interface dll java test

interface: mapscript.i
	$(SWIG) -I../.. -java -package edu.umn.gis.mapscript.imp mapscript.i

dll: mapscript_wrap.c
	$(CC) $(CCFLAGS) $(MAPSCRIPT_FLAGS) $(INCLUDES) -c mapscript_wrap.c
	$(CC) $(CCFLAGS) -shared mapscript_wrap.o ../../libmap.a ../../lib/libregex.a
../../lib/libgd.a ../../lib/libXpm.a ../../lib/libfreetype.a
../../lib/libjpeg_static.a ../../bin/libjpeg.dll ../../lib/libjpeg.a
../../lib/libjpeg_static.a ../../bin/libjpeg.dll ../../lib/libpng.a
../../lib/libttf.a ../../lib/libz.a $(LDFLAGS) -Wl,--add-stdcall-alias -o
mapscript_java.dll

java::
	$(JAVAC) -d . DBFInfo.java MapScript.java MapScriptJNI.java
SWIGTYPE_p_FILE.java SWIGTYPE_p_gdImagePtr.java SWIGTYPE_p_int.java
SWIGTYPE_p_joinObj.java SWIGTYPE_p_p_char.java SWIGTYPE_p_paletteObj.java
SWIGTYPE_p_void.java classObj.java colorObj.java imageObj.java itemObj.java
labelCacheMemberObj.java labelCacheObj.java labelObj.java layerObj.java
legendObj.java lineObj.java mapObj.java markerCacheMemberObj.java pointObj.java
projectionObj.java queryMapObj.java rectObj.java referenceMapObj.java
resultCacheMemberObj.java resultCacheObj.java scalebarObj.java shapeObj.java
shapefileObj.java styleObj.java webObj.java
	$(JAR) cf mapscript_imp.jar edu
	
test::
	$(JAVAC) -classpath mapscript_imp.jar MapScriptTest.java
	$(JAVA) -classpath "mapscript_imp.jar;." MapScriptTest

clean:
	rm -rf edu mapscript_imp.jar *.class mapscript_wrap.o mapscript.o
mapscript_java.dll mapscript_wrap.c mapscript.java mapscriptJNI.java
DBFInfo.java SWIGTYPE_p_FILE.java SWIGTYPE_p_gdImagePtr.java
SWIGTYPE_p_int.java SWIGTYPE_p_joinObj.java SWIGTYPE_p_p_char.java
SWIGTYPE_p_paletteObj.java SWIGTYPE_p_void.java classObj.java colorObj.java
imageObj.java itemObj.java labelCacheMemberObj.java labelCacheObj.java
labelObj.java layerObj.java legendObj.java lineObj.java mapObj.java
markerCacheMemberObj.java pointObj.java projectionObj.java queryMapObj.java
rectObj.java referenceMapObj.java resultCacheMemberObj.java resultCacheObj.java
scalebarObj.java shapeObj.java shapefileObj.java styleObj.java webObj.java

== mapscript.i

//
// mapscript.i: SWIG interface file for MapServer scripting extension called
MapScript.
//

// language specific initialization
#ifdef SWIGTCL8
%module Mapscript
%{

/* static global copy of Tcl interp */
static Tcl_Interp *SWIG_TCL_INTERP;

%}

%init %{
#ifdef USE_TCL_STUBS
  if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
    return TCL_ERROR;
  }
  /* save Tcl interp pointer to be used in getImageToVar() */
  SWIG_TCL_INTERP = interp;
#endif
%}
#endif

// Java specific initialization
#ifdef SWIGJAVA
%module MapScript
#endif

%module mapscript
%{
#include "../../map.h"
#include "../../maptemplate.h"
%}

%include typemaps.i
%include constraints.i

%rename (_class) class;

// Java specific initialization
#ifdef SWIGJAVA
%typemap(javacode) SWIGTYPE %{
  public boolean equals(Object obj)
  {
    boolean equal = false;

    if (obj instanceof $javaclassname)
    {
      equal = ((($javaclassname) obj).swigCPtr == this.swigCPtr);
    }

    return equal;
  }
%}
#endif

// grab mapserver declarations to wrap
%include "../../mapprimitive.h"
%include "../../mapshape.h"
%include "../../mapproject.h"
%include "../../map.h"
// %include "../../maperror.h"

%apply Pointer NONNULL { mapObj *map };
%apply Pointer NONNULL { layerObj *layer };

#ifdef SWIGPYTHON
// For Python, errors reported via the ms_error structure are translated
// into RuntimeError exceptions. (Chris Chamberlin <cdc at aracnet.com>)
%{
  static void _raise_ms_exception(void) {
    char errbuf[256];
    snprintf(errbuf, 255, "%s: %s %s\n", ms_error.routine,
msGetErrorString(ms_error.code), ms_error.message);
    _SWIG_exception(SWIG_RuntimeError, errbuf);
  }

  #define raise_ms_exception() { _raise_ms_exception(); return NULL; }
%}

%except {
  $function
    if ( (ms_error.code != MS_NOERR) && (ms_error.code != -1) )
      raise_ms_exception();
}
#endif // SWIGPYTHON

//
// class extensions for mapObj
//
%extend mapObj {

  mapObj(char *filename) {
    mapObj *map;

    if(filename && strlen(filename))
      return msLoadMap(filename, NULL);
    else { /* create an empty map, no layers etc... */
      map = (mapObj *)malloc(sizeof(mapObj));
      if(!map) {
        msSetError(MS_MEMERR, NULL, "msLoadMap()");
        return NULL;
      }

      initMap(map);
      return map;
    }
  }

  ~mapObj() {
    msFreeMap(self);
  }

  layerObj *getLayer(int i) {
    if(i >= 0 && i < self->numlayers)	
      return &(self->layers[i]); /* returns an EXISTING layer */
    else
      return NULL;
  }

  layerObj *getLayerByName(char *name) {
    int i;

    i = msGetLayerIndex(self, name);

    if(i != -1)
      return &(self->layers[i]); /* returns an EXISTING layer */
    else
      return NULL;
  }

  int addColor(int r, int g, int b) {
    return msAddColor(self, r, g, b);
  }

  int getSymbolByName(char *name) {
    return msGetSymbolIndex(&self->symbolset, name);
  }

  void prepareQuery() {
    int status;

    status = msCalculateScale(self->extent, self->units, self->width,
self->height, self->resolution, &self->scale);
    if(status != MS_SUCCESS) self->scale = -1; // degenerate extents ok here
  }

  imageObj *prepareImage() {
    int status;
    imageObj *image=NULL;

    image = (imageObj *)malloc(sizeof(imageObj));
    if(!image) return NULL;

    if(self->width == -1 || self->height == -1) {
      msSetError(MS_MISCERR, "Image dimensions not specified.",
"prepareImage()");
      return NULL;
    }

    image->bytes = gdImageCreate(self->width, self->height);
    if(!image->bytes) {
      msSetError(MS_GDERR, "Unable to initialize image.", "prepareImage()");
      return NULL;
    }

    image->width = self->width;
    image->height = self->height;
    image->imagepath = image->imageurl = NULL;

    if(msLoadPalette(image->bytes, &(self->palette), self->imagecolor) == -1)
      return NULL;

    self->cellsize = msAdjustExtent(&(self->extent), self->width,
self->height);
    status = msCalculateScale(self->extent, self->units, self->width,
self->height, self->resolution, &self->scale);
    if(status != MS_SUCCESS)
      return NULL;

    return image;
  }

  imageObj *draw() {
    imageObj *image=NULL;

    image = (imageObj *)malloc(sizeof(imageObj));
    if(!image) return NULL;

    image->bytes = msDrawMap(self);
    image->width = gdImageSX(image->bytes);
    image->height = gdImageSY(image->bytes);
    image->imagepath = image->imageurl = NULL;

    return image;
  }

  imageObj *drawQuery() {
    imageObj *image=NULL;

    image = (imageObj *)malloc(sizeof(imageObj));
    if(!image) return NULL;

    image->bytes = msDrawQueryMap(self);
    image->width = gdImageSX(image->bytes);
    image->height = gdImageSY(image->bytes);
    image->imagepath = image->imageurl = NULL;

    return image;
  }

  imageObj *drawLegend() {
    imageObj *image=NULL;

    image = (imageObj *)malloc(sizeof(imageObj));
    if(!image) return NULL;

    image->bytes = msDrawLegend(self);
    image->width = gdImageSX(image->bytes);
    image->height = gdImageSY(image->bytes);
    image->imagepath = image->imageurl = NULL;

    return image;
  }

  imageObj *drawScalebar() {
    imageObj *image=NULL;

    image = (imageObj *)malloc(sizeof(imageObj));
    if(!image) return NULL;

    image->bytes = msDrawScalebar(self);
    image->width = gdImageSX(image->bytes);
    image->height = gdImageSY(image->bytes);
    image->imagepath = image->imageurl = NULL;

    return image;
  }

  imageObj *drawReferenceMap() {
    imageObj *image=NULL;

    image = (imageObj *)malloc(sizeof(imageObj));
    if(!image) return NULL;

    image->bytes = msDrawReferenceMap(self);
    image->width = gdImageSX(image->bytes);
    image->height = gdImageSY(image->bytes);
    image->imagepath = image->imageurl = NULL;

    return image;
  }

  int embedScalebar(imageObj *image) {	
    return msEmbedScalebar(self, image->bytes);
  }

  int embedLegend(imageObj *image) {	
    return msEmbedLegend(self, image->bytes);
  }

  int drawLabelCache(imageObj *image) {
    return msDrawLabelCache(image->bytes, self);
  }

  int getImageToVar(imageObj *image, char *varname) {
    // set a scripting language variable by name with image data
    int size = 0;
    unsigned char *imgbytes;

    // Tcl implementation to define needed variables, initialization
    #ifdef SWIGTCL8
      Tcl_Obj *imgobj;
      int flags = TCL_LEAVE_ERR_MSG;
      /* no other initialization needed */
    #endif

    // Perl implementation to define needed variables, initialization
    #ifdef SWIGPERL
    #endif

    // Python implementation to define needed variables, initialization
    #ifdef SWIGPYTHON
    #endif

    // generic code to get imgbytes, size
    switch (self->imagetype) {
      case(MS_GIF):
        #ifdef USE_GD_GIF
          /* GD /w gif doesn't have gdImageGifPtr() */
          msSetError(MS_MISCERR, "GIF output is not available.",
                              "getImageToVar()");
          return(MS_FAILURE);
        #endif
        break;
      case(MS_PNG):
        #ifdef USE_GD_PNG
          imgbytes = gdImagePngPtr(image->bytes, &size);
        #else
          msSetError(MS_MISCERR, "PNG output is not available.",
                              "getImageToVar()");
          return(MS_FAILURE);
        #endif
        break;
      case(MS_JPEG):
        #ifdef USE_GD_JPEG
          imgbytes = gdImageJpegPtr(image->bytes, &size, self->imagequality);
        #else
          msSetError(MS_MISCERR, "JPEG output is not available.",
                              "getImageToVar()");
          return(MS_FAILURE);
        #endif
        break;
      case(MS_WBMP):
        #ifdef USE_GD_WBMP
          imgbytes = gdImageWBMPPtr(image->bytes, &size, 1);
        #else
          msSetError(MS_MISCERR, "WBMP output is not available.",
                              "getImageToVar()");
          return(MS_FAILURE);
        #endif
        break;
      default:
        msSetError(MS_MISCERR, "Unknown output image type.",
                              "getImageToVar()");
        return(MS_FAILURE);
    }


    // Tcl implementation to set variable
    #ifdef SWIGTCL8
      imgobj = Tcl_NewByteArrayObj(imgbytes, size);
      Tcl_IncrRefCount(imgobj);
      Tcl_SetVar2Ex(SWIG_TCL_INTERP, varname, (char *)NULL, imgobj, flags);
      Tcl_DecrRefCount(imgobj);
      gdFree(imgbytes);
      return MS_SUCCESS;
    #endif

    // Perl implementation to set variable
    #ifdef SWIGPERL
    #endif

    // Python implementation to set variable
    #ifdef SWIGPYTHON
    #endif

    // return failure for unsupported swig languages
    msSetError(MS_MISCERR, "Unsupported scripting language.",
                              "getImageToVar()");
    return MS_FAILURE;
  }

  labelCacheMemberObj *nextLabel() {
    static int i=0;

    if(i<self->labelcache.numlabels)
      return &(self->labelcache.labels[i++]);
    else
      return NULL;	
  }

  int queryByPoint(pointObj *point, int mode, double buffer) {
    return msQueryByPoint(self, -1, mode, *point, buffer);
  }

  int queryByRect(rectObj rect) {
    return msQueryByRect(self, -1, rect);
  }

  int queryByFeatures(int slayer) {
    return msQueryByFeatures(self, -1, slayer);
  }

  int queryByShape(shapeObj *shape) {
    return msQueryByShape(self, -1, shape);
  }

  //int setWKTProjection(char *string) {
  //  return msLoadWKTProjectionString(string, &(self->projection));
  //}

  %new char *getProjection() {
    return msGetProjectionString(&(self->projection));
  }

  int setProjection(char *string) {
    return msLoadProjectionString(&(self->projection), string);
  }

  int save(char *filename) {
    return msSaveMap(self, filename);
  }

  int saveQuery(char *filename) {
    return msSaveQuery(self, filename);
  }

  int saveQueryAsGML(char *filename) {
    return msGMLWriteQuery(self, filename);
  }

  char *getMetaData(char *name) {
    return(msLookupHashTable(self->web.metadata, name));
  }

  int setMetaData(char *name, char *value) {
    if (!self->web.metadata)
        self->web.metadata = msCreateHashTable();
    if (msInsertHashTable(self->web.metadata, name, value) == NULL)
	return MS_FAILURE;
    return MS_SUCCESS;
  }

  int setSymbolSet(char *szFileName)
  {
    msFreeSymbolSet(&self->symbolset);
    msInitSymbolSet(&self->symbolset);

    // Set symbolset filename
    self->symbolset.filename = strdup(szFileName);

    // Symbolset shares same fontset as main mapfile
    self->symbolset.fontset = &(self->fontset);

    return msLoadSymbolSet(&self->symbolset);
  }

  int mapObj_getNumSymbols()
  {
    return self->symbolset.numsymbols;
  }

  int setFontSet(char *szFileName)
  {
    msFreeFontSet(&(self->fontset));
    msInitFontSet(&(self->fontset));

    // Set fontset filename
    self->fontset.filename = strdup(szFileName);

    return msLoadFontSet(&(self->fontset));
  }

  int  moveLayerup(int layerindex) {
        return msMoveLayerUp(self, layerindex);
  }

  int  moveLayerdown(int layerindex) {
        return msMoveLayerDown(self, layerindex);
  }

  int  *getLayersdrawingOrder() {
        return  self->layerorder;
  }

  int   setLayersdrawingOrder(int *panIndexes) {
        return  msSetLayersdrawingOrder(self, panIndexes);
  }

  char *processTemplate(int bGenerateImages, char **names, char **values, int
numentries) {
      return msProcessTemplate(self, bGenerateImages, names, values,
numentries);
  }

  char *processLegendTemplate(char **names, char **values, int numentries) {
    return msProcessLegendTemplate(self, names, values, numentries);
  }


  char *processQueryTemplate(char **names, char **values, int numentries) {
    return msProcessQueryTemplate(self, names, values, numentries);
  }
};

//
// class extensions for layerObj, always within the context of a map
//
%extend layerObj {
  layerObj(mapObj *map) {
    if(map->numlayers == MS_MAXLAYERS) // no room
      return(NULL);

    if(initLayer(&(map->layers[map->numlayers])) == -1)
      return(NULL);

    map->layers[map->numlayers].index = map->numlayers;
    map->layerorder[map->numlayers] = map->numlayers;
    map->numlayers++;

    return &(map->layers[map->numlayers-1]);
  }

  ~layerObj() {
    return; // map deconstructor takes care of it
  }

  int open(char *path) {
    int status;
    status =  msLayerOpen(self, path);
    if (status == MS_SUCCESS) {
        return msLayerGetItems(self);
    }
    return status;
  }

  void close() {
    msLayerClose(self);
  }

  int getShape(shapeObj *shape, int tileindex, int shapeindex) {
    return msLayerGetShape(self, shape, tileindex, shapeindex);
  }

  resultCacheMemberObj *getResult(int i) {
    if(!self->resultcache) return NULL;

    if(i >= 0 && i < self->resultcache->numresults)
      return &self->resultcache->results[i];
    else
      return NULL;
  }

  classObj *getClass(int i) { // returns an EXISTING class
    if(i >= 0 && i < self->numclasses)
      return &(self->class[i]);
    else
      return NULL;
  }

  char *getItem(int i) { // returns an EXISTING item
    if(i >= 0 && i < self->numitems)
      return (self->items[i]);
    else
      return NULL;
  }

  int draw(mapObj *map, imageObj *image) {
    return msDrawLayer(map, self, image->bytes);
  }

  int drawQuery(mapObj *map, imageObj *image) {
    return msDrawLayer(map, self, image->bytes);
  }

  int queryByAttributes(mapObj *map, int mode) {
    return msQueryByAttributes(map, self->index, mode);
  }

  int queryByPoint(mapObj *map, pointObj *point, int mode, double buffer) {
    return msQueryByPoint(map, self->index, mode, *point, buffer);
  }

  int queryByRect(mapObj *map, rectObj rect) {
    return msQueryByRect(map, self->index, rect);
  }

  int queryByFeatures(mapObj *map, int slayer) {
    return msQueryByFeatures(map, self->index, slayer);
  }

  int queryByShape(mapObj *map, shapeObj *shape) {
    return msQueryByShape(map, self->index, shape);
  }

  int setFilter(char *string) {
    return loadExpressionString(&self->filter, string);
  }

  //int setWKTProjection(char *string) {
  //  return msLoadWKTProjectionString(string, &(self->projection));
  //}

  %new char *getProjection() {
    return msGetProjectionString(&(self->projection));
  }

  int setProjection(char *string) {
    return msLoadProjectionString(&(self->projection), string);
  }

  int addFeature(shapeObj *shape) {
    self->connectiontype = MS_INLINE; // set explicitly

    if(insertFeatureList(&(self->features), shape) == NULL)
      return -1;
    else
      return 0;
  }

  char *getMetaData(char *name) {
    return(msLookupHashTable(self->metadata, name));
  }

  int setMetaData(char *name, char *value) {
    if (!self->metadata)
        self->metadata = msCreateHashTable();
    if (msInsertHashTable(self->metadata, name, value) == NULL)
	return MS_FAILURE;
    return MS_SUCCESS;
  }

  // No longer a memory leak, at least with swig 1.3.11. Swig makes a copy
  // of the returned string and then free's it.
  %new char *getWMSFeatureInfoURL(mapObj *map, int click_x, int click_y, int
feature_count, char *info_format) {
    return(msWMSGetFeatureInfoURL(map, self, click_x, click_y, feature_count,
info_format));
  }

};

//
// class extensions for classObj, always within the context of a layer
//
%extend classObj {
  classObj(layerObj *layer) {
    if(layer->numclasses == MS_MAXCLASSES) // no room
      return NULL;

    if(initClass(&(layer->class[layer->numclasses])) == -1)
      return NULL;
    layer->class[layer->numclasses].type = layer->type;

    layer->numclasses++;

    return &(layer->class[layer->numclasses-1]);
  }

  ~classObj() {
    return; // do nothing, map deconstrutor takes care of it all
  }

  int setExpression(char *string) {
    return loadExpressionString(&self->expression, string);
  }

  int setText(layerObj *layer, char *string) {
    return loadExpressionString(&self->text, string);
  }

  char *getMetaData(char *name) {
    return(msLookupHashTable(self->metadata, name));
  }

  int setMetaData(char *name, char *value) {
    if (!self->metadata)
        self->metadata = msCreateHashTable();
    if (msInsertHashTable(self->metadata, name, value) == NULL)
        return MS_FAILURE;
    return MS_SUCCESS;
  }

  int drawLegendIcon(mapObj *map, layerObj *layer, int width, int height,
imageObj *dstImage, int dstX, int dstY) {
    return msDrawLegendIcon(map, layer, self, width, height, dstImage->bytes,
dstX, dstY);
  }

  imageObj *createLegendIcon(mapObj *map, layerObj *layer, int width, int
height) {
    imageObj *image=NULL;

    image = (imageObj *)malloc(sizeof(imageObj));
    if(!image) return NULL;

    image->bytes = msCreateLegendIcon(map, layer, self, width, height);
    image->width = gdImageSX(image->bytes);
    image->height = gdImageSY(image->bytes);
    image->imagepath = image->imageurl = NULL;

    return image;
  }
};

//
// class extensions for pointObj, useful many places
//
%extend pointObj {
  pointObj() {
    return (pointObj *)malloc(sizeof(pointObj));
  }

  ~pointObj() {
    free(self);
  }

  int project(projectionObj *in, projectionObj *out) {
    return msProjectPoint(in, out, self);
  }	

  int draw(mapObj *map, layerObj *layer, imageObj *image, int classindex, char
*text) {
    return msDrawPoint(map, layer, self, image->bytes, classindex, text);
  }

  double distanceToPoint(pointObj *point) {
    return msDistanceBetweenPoints(self, point);
  }

  double distanceToLine(pointObj *a, pointObj *b) {
    return msDistanceFromPointToLine(self, a, b);
  }

  double distanceToShape(shapeObj *shape) {
    switch(shape->type) {
    case(MS_SHAPE_POINT):
      return msDistanceFromPointToMultipoint(self, &(shape->line[0]));
    case(MS_SHAPE_LINE):
      return msDistanceFromPointToPolyline(self, shape);
    case(MS_SHAPE_POLYGON):
      return msDistanceFromPointToPolygon(self, shape);
    }

    return -1;
  }
};

//
// class extensions for lineObj (eg. a line or group of points), useful many
places
//
%extend lineObj {
  lineObj() {
    lineObj *line;

    line = (lineObj *)malloc(sizeof(lineObj));
    if(!line)
      return(NULL);

    line->numpoints=0;
    line->point=NULL;

    return line;
  }

  ~lineObj() {
    free(self->point);
    free(self);		
  }

  int project(projectionObj *in, projectionObj *out) {
    return msProjectLine(in, out, self);
  }

  pointObj *get(int i) {
    if(i<0 || i>=self->numpoints)
      return NULL;
    else
      return &(self->point[i]);
  }

  int add(pointObj *p) {
    if(self->numpoints == 0) { /* new */	
      self->point = (pointObj *)malloc(sizeof(pointObj));
      if(!self->point)
	return -1;
    } else { /* extend array */
      self->point = (pointObj *)realloc(self->point,
sizeof(pointObj)*(self->numpoints+1));
      if(!self->point)
	return -1;
    }

    self->point[self->numpoints].x = p->x;
    self->point[self->numpoints].y = p->y;
    self->numpoints++;

    return 0;
  }
};

//
// class extensions for shapeObj
//
%extend shapeObj {
  shapeObj(int type) {
    shapeObj *shape;

    shape = (shapeObj *)malloc(sizeof(shapeObj));
    if(!shape)
      return NULL;

    msInitShape(shape);
    if(type >= 0) shape->type = type;

    return shape;
  }

  ~shapeObj() {
    msFreeShape(self);
    free(self);		
  }

  int project(projectionObj *in, projectionObj *out) {
    return msProjectShape(in, out, self);
  }

  lineObj *get(int i) {
    if(i<0 || i>=self->numlines)
      return NULL;
    else
      return &(self->line[i]);
  }

  int add(lineObj *line) {
    return msAddLine(self, line);
  }

  int draw(mapObj *map, layerObj *layer, imageObj *image) {
    return msDrawShape(map, layer, self, image->bytes, MS_TRUE);
  }

  void setBounds() {
    int i, j;

    self->bounds.minx = self->bounds.maxx = self->line[0].point[0].x;
    self->bounds.miny = self->bounds.maxy = self->line[0].point[0].y;

    for( i=0; i<self->numlines; i++ ) {
      for( j=0; j<self->line[i].numpoints; j++ ) {
	self->bounds.minx = MS_MIN(self->bounds.minx, self->line[i].point[j].x);
	self->bounds.maxx = MS_MAX(self->bounds.maxx, self->line[i].point[j].x);
	self->bounds.miny = MS_MIN(self->bounds.miny, self->line[i].point[j].y);
	self->bounds.maxy = MS_MAX(self->bounds.maxy, self->line[i].point[j].y);
      }
    }

    return;
  }

  int copy(shapeObj *dest) {
    return(msCopyShape(self, dest));
  }

  char *getValue(int i) { // returns an EXISTING value
    if(i >= 0 && i < self->numvalues)
      return (self->values[i]);
    else
      return NULL;
  }

  int contains(pointObj *point) {
    if(self->type == MS_SHAPE_POLYGON)
      return msIntersectPointPolygon(point, self);

    return -1;
  }

  int intersects(shapeObj *shape) {
    switch(self->type) {
    case(MS_SHAPE_LINE):
      switch(shape->type) {
      case(MS_SHAPE_LINE):
	return msIntersectPolylines(self, shape);
      case(MS_SHAPE_POLYGON):
	return msIntersectPolylinePolygon(self, shape);
      }
      break;
    case(MS_SHAPE_POLYGON):
      switch(shape->type) {
      case(MS_SHAPE_LINE):
	return msIntersectPolylinePolygon(shape, self);
      case(MS_SHAPE_POLYGON):
	return msIntersectPolygons(self, shape);
      }
      break;
    }

    return -1;
  }
};

//
// class extensions for rectObj
//
%extend rectObj {
  rectObj() {	
    rectObj *rect;

    rect = (rectObj *)calloc(1, sizeof(rectObj));
    if(!rect)
      return(NULL);

    return(rect);    	
  }

  ~rectObj() {
    free(self);
  }

  int project(projectionObj *in, projectionObj *out) {
    return msProjectRect(in, out, self);
  }

  double fit(int width, int height) {
    return  msAdjustExtent(self, width, height);
  }

  int draw(mapObj *map, layerObj *layer, imageObj *image, int classindex, char
*text) {
    shapeObj shape;

    msInitShape(&shape);
    msRectToPolygon(*self, &shape);
    shape.classindex = classindex;
    shape.text = strdup(text);

    msDrawShape(map, layer, &shape, image->bytes, MS_TRUE);

    msFreeShape(&shape);

    return 0;
  }
};

//
// class extensions for shapefileObj
//
%extend shapefileObj {
  shapefileObj(char *filename, int type) {
    shapefileObj *shapefile;
    int status;

    shapefile = (shapefileObj *)malloc(sizeof(shapefileObj));
    if(!shapefile)
      return NULL;

    if(type == -1)
      status = msSHPOpenFile(shapefile, "rb", NULL, filename);
    else if(type == -2)
      status = msSHPOpenFile(shapefile, "rb+", NULL, filename);
    else
      status = msSHPCreateFile(shapefile, filename, type);

    if(status == -1) {
      msSHPCloseFile(shapefile);
      free(shapefile);
      return NULL;
    }

    return(shapefile);
  }

  ~shapefileObj() {
    msSHPCloseFile(self);
    free(self);
  }

  int get(int i, shapeObj *shape) {
    if(i<0 || i>=self->numshapes)
      return -1;

    msFreeShape(shape); /* frees all lines and points before re-filling */
    msSHPReadShape(self->hSHP, i, shape);

    return 0;
  }

  int getPoint(int i, pointObj *point) {
    if(i<0 || i>=self->numshapes)
      return -1;

    msSHPReadPoint(self->hSHP, i, point);
    return 0;
  }

  int getTransformed(mapObj *map, int i, shapeObj *shape) {
    if(i<0 || i>=self->numshapes)
      return -1;

    msFreeShape(shape); /* frees all lines and points before re-filling */
    msSHPReadShape(self->hSHP, i, shape);
    msTransformShape(shape, map->extent, map->cellsize);

    return 0;
  }

  void getExtent(int i, rectObj *rect) {
    msSHPReadBounds(self->hSHP, i, rect);
  }

  int add(shapeObj *shape) {
    return msSHPWriteShape(self->hSHP, shape);	
  }	

  int addPoint(pointObj *point) {
    return msSHPWritePoint(self->hSHP, point);	
  }
};

//
// class extensions for imageObj
//
%extend imageObj {
  imageObj(int width, int height) {
    imageObj *image=NULL;

    image = (imageObj *)malloc(sizeof(imageObj));
    if(!image) return NULL;

    image->bytes = gdImageCreate(width, height);
    image->width = width;
    image->height = height;
    image->imagepath = image->imageurl = NULL;

    return(image);
  }

  ~imageObj() {
    gdImageDestroy(self->bytes);
    free(self->imagepath);
    free(self->imageurl);
    free(self);		
  }

  void free() {
    gdImageDestroy(self->bytes);
    free(self->imagepath);
    free(self->imageurl);
    free(self);
  }

  void saveImage(char *filename, int type, int transparent, int interlace, int
quality) {
    msSaveImage(self->bytes, filename, type, transparent, interlace, quality);
  }

};

//
// class extensions for projectionObj
//
%extend projectionObj {
  projectionObj(char *string) {
    int status;
    projectionObj *proj=NULL;

    proj = (projectionObj *)malloc(sizeof(projectionObj));
    if(!proj) return NULL;
    msInitProjection(proj);

    status = msLoadProjectionString(proj, string);
    if(status == -1) {
      msFreeProjection(proj);
      free(proj);
      return NULL;
    }

    return proj;
  }

  ~projectionObj() {
    msFreeProjection(self);
    free(self);		
  }
};


//
// class extensions for labelCacheObj - TP mods
//
%extend labelCacheObj {

  void freeCache() {
    int i;
    for (i = 0; i < self->numlabels; i++) {
        free(self->labels[i].string);
        msFreeShape(self->labels[i].poly);
    }
    self->numlabels = 0;
    for (i = 0; i < self->nummarkers; i++) {
        msFreeShape(self->markers[i].poly);
    }
    self->nummarkers = 0;
  }

};

//
// class extensions for DBFInfo - TP mods
//
%extend DBFInfo {
    char *getFieldName(int iField) {
        static char pszFieldName[1000];
	int pnWidth;
	int pnDecimals;
	msDBFGetFieldInfo(self, iField, &pszFieldName[0], &pnWidth, &pnDecimals);
	return pszFieldName;
    }

    int getFieldWidth(int iField) {
        char pszFieldName[1000];
	int pnWidth;
	int pnDecimals;
	msDBFGetFieldInfo(self, iField, &pszFieldName[0], &pnWidth, &pnDecimals);
	return pnWidth;
    }

    int getFieldDecimals(int iField) {
        char pszFieldName[1000];
	int pnWidth;
	int pnDecimals;
	msDBFGetFieldInfo(self, iField, &pszFieldName[0], &pnWidth, &pnDecimals);
	return pnDecimals;
    }

    int getFieldType(int iField) {
	return msDBFGetFieldInfo(self, iField, NULL, NULL, NULL);
    }
};

== MapScriptTest.java

/* File : main.java */

import edu.umn.gis.mapscript.imp.*;

public class MapScriptTest
{

  static
  {
    try
    {
      System.loadLibrary("mapscript_java");
    }
    catch (UnsatisfiedLinkError e)
    {
      System.err.println("Native code library failed to load.\n");
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    System.out.println("MapScript.MS_SHAPEFILE_POINT=[" +
MapScript.MS_SHAPEFILE_POINT + "]");
    System.out.println("MapScript.MS_SHAPEFILE_ARC=[" +
MapScript.MS_SHAPEFILE_ARC + "]");
    System.out.println("MapScript.MS_SHAPEFILE_POLYGON=[" +
MapScript.MS_SHAPEFILE_POLYGON + "]");
    System.out.println("MapScript.MS_SHAPEFILE_MULTIPOINT=[" +
MapScript.MS_SHAPEFILE_MULTIPOINT + "]");
    System.out.println("MapScript.MS_SHP_POINTM=[" + MapScript.MS_SHP_POINTM +
"]");
    System.out.println("MapScript.MS_SHP_ARCM=[" + MapScript.MS_SHP_ARCM +
"]");
    System.out.println("MapScript.MS_SHP_POLYGONM=[" +
MapScript.MS_SHP_POLYGONM + "]");
    System.out.println("MapScript.MS_SHP_MULTIPOINTM=[" +
MapScript.MS_SHP_MULTIPOINTM + "]");
    System.out.println("MapScript.FTString=[" + MapScript.FTString + "]");
    System.out.println("MapScript.FTInteger=[" + MapScript.FTInteger + "]");
    System.out.println("MapScript.FTDouble=[" + MapScript.FTDouble + "]");
    System.out.println("MapScript.FTInvalid=[" + MapScript.FTInvalid + "]");
    System.out.println("MapScript.MS_VERSION=[" + MapScript.MS_VERSION + "]");
    System.out.println("MapScript.MS_TRUE=[" + MapScript.MS_TRUE + "]");
    System.out.println("MapScript.MS_FALSE=[" + MapScript.MS_FALSE + "]");
    System.out.println("MapScript.MS_ON=[" + MapScript.MS_ON + "]");
    System.out.println("MapScript.MS_OFF=[" + MapScript.MS_OFF + "]");
    System.out.println("MapScript.MS_DEFAULT=[" + MapScript.MS_DEFAULT + "]");
    System.out.println("MapScript.MS_EMBED=[" + MapScript.MS_EMBED + "]");
    System.out.println("MapScript.MS_DELETE=[" + MapScript.MS_DELETE + "]");
    System.out.println("MapScript.MS_YES=[" + MapScript.MS_YES + "]");
    System.out.println("MapScript.MS_NO=[" + MapScript.MS_NO + "]");
    System.out.println("MapScript.MS_SINGLE=[" + MapScript.MS_SINGLE + "]");
    System.out.println("MapScript.MS_MULTIPLE=[" + MapScript.MS_MULTIPLE +
"]");
    System.out.println("MapScript.MS_FILE_MAP=[" + MapScript.MS_FILE_MAP +
"]");
    System.out.println("MapScript.MS_FILE_SYMBOL=[" + MapScript.MS_FILE_SYMBOL
+ "]");
    System.out.println("MapScript.MS_INCHES=[" + MapScript.MS_INCHES + "]");
    System.out.println("MapScript.MS_FEET=[" + MapScript.MS_FEET + "]");
    System.out.println("MapScript.MS_MILES=[" + MapScript.MS_MILES + "]");
    System.out.println("MapScript.MS_METERS=[" + MapScript.MS_METERS + "]");
    System.out.println("MapScript.MS_KILOMETERS=[" + MapScript.MS_KILOMETERS +
"]");
    System.out.println("MapScript.MS_DD=[" + MapScript.MS_DD + "]");
    System.out.println("MapScript.MS_PIXELS=[" + MapScript.MS_PIXELS + "]");
    System.out.println("MapScript.MS_SHAPE_POINT=[" + MapScript.MS_SHAPE_POINT
+ "]");
    System.out.println("MapScript.MS_SHAPE_LINE=[" + MapScript.MS_SHAPE_LINE +
"]");
    System.out.println("MapScript.MS_SHAPE_POLYGON=[" +
MapScript.MS_SHAPE_POLYGON + "]");
    System.out.println("MapScript.MS_SHAPE_NULL=[" + MapScript.MS_SHAPE_NULL +
"]");
    System.out.println("MapScript.MS_LAYER_POINT=[" + MapScript.MS_LAYER_POINT
+ "]");
    System.out.println("MapScript.MS_LAYER_LINE=[" + MapScript.MS_LAYER_LINE +
"]");
    System.out.println("MapScript.MS_LAYER_POLYGON=[" +
MapScript.MS_LAYER_POLYGON + "]");
    System.out.println("MapScript.MS_LAYER_RASTER=[" +
MapScript.MS_LAYER_RASTER + "]");
    System.out.println("MapScript.MS_LAYER_ANNOTATION=[" +
MapScript.MS_LAYER_ANNOTATION + "]");
    System.out.println("MapScript.MS_LAYER_QUERY=[" + MapScript.MS_LAYER_QUERY
+ "]");
    System.out.println("MapScript.MS_LAYER_CIRCLE=[" +
MapScript.MS_LAYER_CIRCLE + "]");
    System.out.println("MapScript.MS_TRUETYPE=[" + MapScript.MS_TRUETYPE +
"]");
    System.out.println("MapScript.MS_BITMAP=[" + MapScript.MS_BITMAP + "]");
    System.out.println("MapScript.MS_UL=[" + MapScript.MS_UL + "]");
    System.out.println("MapScript.MS_LR=[" + MapScript.MS_LR + "]");
    System.out.println("MapScript.MS_UR=[" + MapScript.MS_UR + "]");
    System.out.println("MapScript.MS_LL=[" + MapScript.MS_LL + "]");
    System.out.println("MapScript.MS_CR=[" + MapScript.MS_CR + "]");
    System.out.println("MapScript.MS_CL=[" + MapScript.MS_CL + "]");
    System.out.println("MapScript.MS_UC=[" + MapScript.MS_UC + "]");
    System.out.println("MapScript.MS_LC=[" + MapScript.MS_LC + "]");
    System.out.println("MapScript.MS_CC=[" + MapScript.MS_CC + "]");
    System.out.println("MapScript.MS_AUTO=[" + MapScript.MS_AUTO + "]");
    System.out.println("MapScript.MS_XY=[" + MapScript.MS_XY + "]");
    System.out.println("MapScript.MS_TINY=[" + MapScript.MS_TINY + "]");
    System.out.println("MapScript.MS_SMALL=[" + MapScript.MS_SMALL + "]");
    System.out.println("MapScript.MS_MEDIUM=[" + MapScript.MS_MEDIUM + "]");
    System.out.println("MapScript.MS_LARGE=[" + MapScript.MS_LARGE + "]");
    System.out.println("MapScript.MS_GIANT=[" + MapScript.MS_GIANT + "]");
    System.out.println("MapScript.MS_NORMAL=[" + MapScript.MS_NORMAL + "]");
    System.out.println("MapScript.MS_HILITE=[" + MapScript.MS_HILITE + "]");
    System.out.println("MapScript.MS_SELECTED=[" + MapScript.MS_SELECTED +
"]");
    System.out.println("MapScript.MS_INLINE=[" + MapScript.MS_INLINE + "]");
    System.out.println("MapScript.MS_SHAPEFILE=[" + MapScript.MS_SHAPEFILE +
"]");
    System.out.println("MapScript.MS_TILED_SHAPEFILE=[" +
MapScript.MS_TILED_SHAPEFILE + "]");
    System.out.println("MapScript.MS_SDE=[" + MapScript.MS_SDE + "]");
    System.out.println("MapScript.MS_OGR=[" + MapScript.MS_OGR + "]");
    System.out.println("MapScript.MS_UNUSED_1=[" + MapScript.MS_UNUSED_1 +
"]");
    System.out.println("MapScript.MS_POSTGIS=[" + MapScript.MS_POSTGIS + "]");
    System.out.println("MapScript.MS_WMS=[" + MapScript.MS_WMS + "]");
    System.out.println("MapScript.MS_ORACLESPATIAL=[" +
MapScript.MS_ORACLESPATIAL + "]");
    System.out.println("MapScript.MS_GIF=[" + MapScript.MS_GIF + "]");
    System.out.println("MapScript.MS_PNG=[" + MapScript.MS_PNG + "]");
    System.out.println("MapScript.MS_JPEG=[" + MapScript.MS_JPEG + "]");
    System.out.println("MapScript.MS_WBMP=[" + MapScript.MS_WBMP + "]");
    System.out.println("MapScript.MS_GML=[" + MapScript.MS_GML + "]");
    System.out.println("MapScript.MS_CJC_NONE=[" + MapScript.MS_CJC_NONE +
"]");
    System.out.println("MapScript.MS_CJC_BEVEL=[" + MapScript.MS_CJC_BEVEL +
"]");
    System.out.println("MapScript.MS_CJC_BUTT=[" + MapScript.MS_CJC_BUTT +
"]");
    System.out.println("MapScript.MS_CJC_MITER=[" + MapScript.MS_CJC_MITER +
"]");
    System.out.println("MapScript.MS_CJC_ROUND=[" + MapScript.MS_CJC_ROUND +
"]");
    System.out.println("MapScript.MS_CJC_SQUARE=[" + MapScript.MS_CJC_SQUARE +
"]");
    System.out.println("MapScript.MS_CJC_TRIANGLE=[" +
MapScript.MS_CJC_TRIANGLE + "]");
    System.out.println("MapScript.MS_SUCCESS=[" + MapScript.MS_SUCCESS + "]");
    System.out.println("MapScript.MS_FAILURE=[" + MapScript.MS_FAILURE + "]");
    System.out.println("MapScript.MS_DONE=[" + MapScript.MS_DONE + "]");
  }
}





=====
Andrew Collins - andrewrcollins at yahoo.com
http://profiles.yahoo.com/andrewrcollins/

__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/



More information about the mapserver-users mailing list