Modifying EsriLayerclass

From: Rajesh G S <gsronline@yahoo.com>
Date: Tue Mar 12 2002 - 03:09:58 EST

Hi All,

I have tried to extend the EsriLayer class. The idea was to add a method
such that we can set the properties of the layer to display different
formatting like random color, color based on a range value etc.

I havent applied the graphics to the layer. What this tries is to declare an
empty EsriLayer and then add the records & graphics using the addRecord
method of the super class. I have initialised some variables but havent used
them. Once I get the layer to display, I will modify it.

I would like to know is theres a better implementation.

import com.bbn.openmap.plugin.esri.*;
import com.bbn.openmap.layer.shape.areas.*;
import com.bbn.openmap.proj.Projection;
import com.bbn.openmap.omGraphics.*;
import com.bbn.openmap.util.*;
import com.bbn.openmap.layer.util.*;
import com.bbn.openmap.omGraphics.DrawingAttributes;
import com.bbn.openmap.plugin.esri.input.DbfInputStream;

import java.net.URL;
import java.net.MalformedURLException;
import java.util.*;
import java.awt.Color;
import java.io.*;

/*
Descn: An ESRI Layer implementation which takes in properties object and
format the layer objects.

Required property fields:
tblIndex = The ref. field in the shape table default=0
default.* = Settings for which no format has been defined (lineColor,
lineWidth, fillColor etc)
areas = The index of areas to be formatted
areas.* = The formatting to be applied for different indexes
*/
public class EsriShapeLayer extends EsriLayer {
        private String _name;
        private EsriGraphicList _list = null;
        private DbfTableModel _table = null;
        private Properties _props;
        private String _prefix;
        private int _tblIndex = 0;
        private Hashtable _areasList;
        private DrawingAttributes _dpa;
        private Projection _projection;

        public final static String tblIndexProperty = "tblIndex";
        public final static String areasProperty = "areas";
        public final static String defaultProperty = "default";

        //constructor: loads the shape, index &* dbf
        public EsriShapeLayer(String name, String filename) {
                File dbf = new File(filename + ".dbf");
                File shp = new File(filename + ".shp");
                File shx = new File(filename + ".shx");

                try {
                        _list = getGeometry(shp.toURL(), shx.toURL());
                        _table = getDbfTableModel(dbf.toURL());
                }
                catch(Exception exception) {
                        System.out.println(exception);
                        return;
                }
        }

        //Gets the vector from which grafik formatting is to be applied to
the shape
        public void setProperties(String prefix, Properties props) {
                if (prefix == null || props == null) return;
                _prefix = prefix;
                _props = props;
                //apply the drawing attrib
                initialize();
                computeGraphics();
        }

        /*
        Add the graphics to the Esri Layer
        */
        public void computeGraphics() {
                if (_list == null || _table == null) {
                        System.out.println("No areas has been set to format
graphics");
                        return;
                }
                //loop thru the _table.
                int rows = _table.getRowCount();
                int cols = _table.getColumnCount();
                //generate graphics
                for (int i=0;i<rows;i++) {
                        OMGraphic omg = _list. getOMGraphicAt(i);
                        ArrayList record = new ArrayList(cols);
                        for (int j=0;j<cols;j++)
record.add(_table.getValueAt(i,j));
                        super.addRecord(omg,record);
                        record = null;
                }
        }

        /*
        This method will extract & set all the properties to appropriate
variables

        the properties need to contain:
        tblIndex: The column which is used as ref. field
        areas: an index of the group values
        default drawingAttributes (line color, fill color, line width,
pattern etc)
        attributes for different areas
        */

        public void initialize() {
                //xtract & set tblindex
                _tblIndex = LayerUtils.intFromProperties(_props, _prefix +
tblIndexProperty, _tblIndex);

                //xtract & set default da
                _dpa = new DrawingAttributes(_prefix + defaultProperty,
_props);

                //xtract & set areas list

                String areas = _props.getProperty(_prefix+areasProperty);
                if (areas == null) areas = "";
                StringTokenizer tokenizer = new StringTokenizer(areas,",");
                String currentArea;
                String currentAreaColorStr;
                String currentAreaFillPatternStr;
                Color currentAreaColor;

                while (tokenizer.hasMoreTokens()) {
                        currentArea = tokenizer.nextToken();

                        PoliticalArea newParams = new
PoliticalArea(currentArea);
                        System.out.println("AreaHandler: setting SPECIALIZED
attributes for \"" + newParams.id + "\"");

                        newParams.setDrawingAttributes( new
DrawingAttributes(_prefix + areasProperty + "." + currentArea, _props));
                        _areasList.put(newParams.id.toUpperCase().intern(),
newParams);
                }

        }

        public void setDrawingAttributes(DrawingAttributes da) {
                _dpa = da;
        }

        private DbfTableModel getDbfTableModel(URL dbf) {
                URL url;
                DbfTableModel model = null;
                try {
                        InputStream is = dbf.openStream();
                        try{
                                model = new DbfTableModel(new
DbfInputStream(is));
                        }
                        catch(Exception exception) {
                                System.out.println(exception);
                        }
                }
                catch(Exception exception) {
                        System.out.println(exception);
                }
                return model;
        }
}

Yea, I know this is a dumb implementation.

Thanx

Rajesh

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

--
[To unsubscribe to this list send an email to "majdart@bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Tue Mar 12 03:11:05 2002

This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:32 EDT