Create a shapefile using Java Mapscript

Sean Gillies sgillies at FRII.COM
Thu Apr 21 09:49:43 EDT 2005


On Apr 21, 2005, at 6:43 AM, Libo Feng wrote:

> I am a newbie to Java mapscript and in my project, I need to
> dynamically
> create a shape file that contains a point. The coordinate of that
> point is
> from an address matching web service. I am able to create the .shp,
> .shx
> files with the mapscript and a .dbf file with Javadbf. But the .shp
> and .shx
> seem to be empty - when I open it with ArcExplorer, there is no point
> at all.
>
> The following is the code:
>
> shapefileObj civicAddressShp = new shapefileObj(shapeFile,
>
> mapscriptConstants.MS_SHAPEFILE_POINT);
> pointObj addressPoint = new pointObj(x, y, 0.0, Double.MIN_VALUE);
> civicAddressShp.addPoint(addressPoint);
>
>
> Did I miss anything? Thanks!
>

Yes, what you missed is that the point isn't written to the file on
disk until the shapefileObj is "closed".  The only way to close it is
by triggering its destructor.  It's awkward, but that's just the way it
is.

cheers,
Sean

--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies



More information about the mapserver-users mailing list