[mapserver-users] Re: How to add attributes to feature/shape with mapscript java?

rai 8 max1000 at gmail.com
Wed Dec 8 06:39:00 PST 2010


Hi!,

Finaly I found the way set the id of a feature, mapscript maps the last
value set by setvalue with layer.setClassItem ,but I only can add a one
attribute with layer.setFilteritem("itemName");

// Features add
for (Iterator iterator = sites.iterator(); iterator.hasNext();) {

          Site site = (Site) iterator.next();
    shapeObj shape = new shapeObj( mapscriptConstants.MS_SHP_POINTM );
    lineObj line = new lineObj();

    // latlon source data
    pointObj point = new pointObj( site.getLatLonPosition().getX() ,
site.getLatLonPosition().getY() , 0);

    shape = point.toShape();

    shape.initValues(2);
    shape.setValue(0, site.getId().toString() ); // ID
    layer.addFeature(shape );
 }
}

layer.setClassitem("id");

I think that the way to add many attributes is with layer.SetItems but isn't
implemented in mapscript swig, I found in maplayer.c msLayerSetItems function,
why setlayerItem is not appear in mapscript?

/*
** A helper function to set the items to be retrieved with a particular
shape. Unused at the moment but will be used
** from within MapScript. Should not need modification.
*/
int msLayerSetItems(layerObj *layer, char **items, int numitems)


Another problem that I have is to reproject the data, It seems that there is
a bug with reprojections in mapscript, if projection map and projection
layer is not the same the reprojected coordinates aren't correct. Also if I
try to reproject manualy the coordinates are wrong. I'm leaving something?

projectionObj proj4326 = new projectionObj("EPSG:4326");
    projectionObj proj32631 = new projectionObj("EPSG:32631");
    point.project(proj4326, proj32631);


thanks!

2010/12/6 rai 8 <max1000 at gmail.com>

>
> Hi!,
>
> I trying to add features to a layer with mapscript in a WFS server, there
> isn't any method to set attributes directly to a feature or a shape.
>
> I found initValues and setValue to set value to a shape object but in a
> xml/gml response it doesn't appear. Anyone knows a way to do this?
>
>  // add feature
>     shapeObj shape = new shapeObj( mapscriptConstants.MS_SHP_POINTM );
>     shape.initValues(8);
>     lineObj line = new lineObj();
>     pointObj point = new pointObj(2.160690, 41.479881, 1);
>     line.add(point);
>     shape.add( line);
>     shape.setValue(0, "attr1");
>     shape.setValue(1, "attr2");
>     System.out.println( shape.getValue(0) + " " + shape.getValue(1) + " " +
> shape.getValue(2) );
>  layer.addFeature(shape );
>  shape = new shapeObj( mapscriptConstants.MS_SHP_POINTM );
>     line = new lineObj();
>     point = new pointObj(2.170000, 41.480000, 1);
>     line.add(point);
>     shape.add( line);
> layer.addFeature(shape );
>
> Another workaround I found is generated a dbf file with all features and
> attributes that I want and then load a mapfile pointing to this dbf file,
> but this is inefficient.
>
>
> thanks!
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20101208/f773cd99/attachment.htm>


More information about the MapServer-users mailing list