Re: [OpenMap Users] creating layer using zcta data from us census

From: Adam Russell <adam.russell@channing.harvard.edu>
Date: Thu Jul 31 2003 - 11:39:46 EDT

Don and Martin,
Thank you for all your very helpful advice(and code even!!>:) . The
solution I am happy with for now is to use
EsriLayer to get the full EsriGraphicList and then pull out the
OMGraphic of interest based on the index corresponding to record of
interest in the dbf file. I then just setFillPaint to some color.

           OMGraphicList oGraphicList = new OMGraphicList();
            try{
                File dbf = new File("data/shape/zt25_d00.dbf");
                File shp = new File("data/shape/zt25_d00.shp");
                File shx = new File("data/shape/zt25_d00.shx");
                EsriLayer el=new EsriLayer("PUKE", dbf.toURL(),
shp.toURL(), shx.toURL());
                EsriGraphicList egl=el.getGeometry(shp.toURL(),
shx.toURL());
                OMGraphic og=egl.getOMGraphicAt(326);//stupid hardcoded
for now. 326 corresponds to Weymouth, MA in the dbf.
                System.out.println(og.getDescription());
                og.setFillPaint(java.awt.Color.RED);
                oGraphicList.add(og);
            }
            catch(Exception e){
                e.printStackTrace();
            }

Thanks again!!

Don Dietrick wrote:

> Oh, you'll want to use the
> com.bbn.openmap.layer.shape.areas.AreaShapeLayer.
>
> - Don
>
> On Wednesday, July 30, 2003, at 06:44 PM, Adam Russell wrote:
>
>> Thanks but I can only wonder if there isn't an even easier way of
>> doing all I want. Basically all I want to do is change the color of
>> certain regions on the map. The regions are defined in the shp file
>> which, as from what Don said, are mapped to the dbf file.
>> I have no problem reading the contents of the dbf file at all with
>> the DbfTableModel class.
>> The following bit of code seemingly creates an EsriPolygonList of all
>> my polygons(is that right?)
>>
>> File dbf = new File("data/shape/zt25_d00.dbf");
>> File shp = new File("data/shape/zt25_d00.shp");
>> File shx = new File("data/shape/zt25_d00.shx");
>> EsriPlugIn epi = new EsriPlugIn("name", dbf.toURL(),
>> shp.toURL(), shx.toURL());
>> PlugInLayer pil = new PlugInLayer();
>> pil.setPlugIn(epi);
>> OMGraphicList ogl=pil.prepare();
>> EsriPolygonList epl=new EsriPolygonList();
>> Iterator iter=ogl.iterator();
>> while(iter.hasNext()){
>> epl.add((OMGraphic)iter.next());
>> }
>>
>> So, from what I can tell, I have a list of polygons which correspond
>> to the regions on my map, right? Can I now selectively manipulate
>> ones that I want and draw them over my existing map?
>> Sorry if I am being dense here.......
>>
>> Martin Chapman wrote:
>>
>>> Adam,
>>>
>>> You can use the cvs location layer in the openmap.properties file for
>>> this operation if you want labels on the map for a layer using the
>>> SimpleHttpImageServer. If you need more control then retrieve the
>>> image
>>> from the image server first in your servlet, jsp, etc using a URL
>>> object
>>> an Image object, then once the image is returned you can use the
>>> openmap
>>> api to further draw detail on the image. Here is some example
>>> code. It
>>> basically retrieves the map image from the SimpleHttpImageServer and
>>> then draws a polygon on top of the image using the openamp api. Let me
>>> know if this will work. You can change the polygon code to open a .dbf
>>> file and then do what Don said.
>>>
>>> private void getMapImage(HttpServletRequest request,
>>> HttpServletResponse
>>> response) throws ServletException, IOException
>>> {
>>> try
>>> {
>>> HttpSession oSession = request.getSession();
>>> String sRequestURI = request.getRequestURI();
>>> String sQueryString = request.getQueryString();
>>> StringBuffer sHrefBuffer = new StringBuffer();
>>> sHrefBuffer.append("..");
>>> sHrefBuffer.append(sRequestURI);
>>> sHrefBuffer.append("?");
>>> sHrefBuffer.append(sQueryString);
>>>
>>> int nProjType =
>>> ProjectionFactory.getProjType(getProjectionType(request));
>>> SunJPEGFormatter oFormatter = new SunJPEGFormatter();
>>> oFormatter.setImageQuality(100.0f);
>>> Frame oFrame = new Frame();
>>> OMGraphicList oGraphicList = new OMGraphicList();
>>> Projection oProjection =
>>> ProjectionFactory.makeProjection(nProjType,
>>> getLatitude(request),
>>> getLongitude(request),
>>> getScale(request),
>>> getWidth(request),
>>> getHeight(request));
>>>
>>> String sAOIVertices = getAOIVertices(request);
>>>
>>> if (sAOIVertices.length() > 0)
>>> {
>>> oGraphicList.setTraverseMode(OMGraphicList.LAST_ADDED_ON_TOP);
>>> String[] sVerticesArray = sAOIVertices.split(",");
>>>
>>> float[] llPoints = new float[sVerticesArray.length];
>>>
>>> for (int i = 0; i < (sVerticesArray.length);)
>>> {
>>> double nLat = Double.parseDouble(sVerticesArray[i]);
>>> llPoints[i] = (float) nLat;
>>> i++;
>>> double nLon = Double.parseDouble(sVerticesArray[i]);
>>> llPoints[i] = (float) nLon;
>>> i++;
>>> }
>>>
>>> EsriPolygon oEsriPolygon = new EsriPolygon(llPoints,
>>> OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_STRAIGHT);
>>> oEsriPolygon.setLinePaint(new Color(0, 0, 255));
>>> oEsriPolygon.setFillPaint(new Color(0, 0, 255, 15));
>>> oEsriPolygon.setStroke(new BasicStroke(2.0f));
>>> oGraphicList.add(oEsriPolygon);
>>> }
>>>
>>> StringBuffer sUrlBuffer = new StringBuffer();
>>>
>>> sUrlBuffer.append("http://");
>>> sUrlBuffer.append(m_sHostName);
>>> sUrlBuffer.append(":");
>>> sUrlBuffer.append(m_nPort);
>>> sUrlBuffer.append("/openmap?REQUEST=MAP");
>>> sUrlBuffer.append("&LAT=");
>>> sUrlBuffer.append(getLatitude(request));
>>> sUrlBuffer.append("&LON=");
>>> sUrlBuffer.append(getLongitude(request));
>>> sUrlBuffer.append("&SCALE=");
>>> sUrlBuffer.append(getScale(request));
>>> sUrlBuffer.append("&PROJTYPE=");
>>> sUrlBuffer.append(getProjectionType(request));
>>> sUrlBuffer.append("&HEIGHT=");
>>> sUrlBuffer.append(getHeight(request));
>>> sUrlBuffer.append("&WIDTH=");
>>> sUrlBuffer.append(getWidth(request));
>>> sUrlBuffer.append("&BGCOLOR=");
>>> sUrlBuffer.append(getBGColor(request));
>>> sUrlBuffer.append("&LAYERS=");
>>> sUrlBuffer.append(getLayers(request));
>>>
>>> String s = sUrlBuffer.toString();
>>>
>>> URL oUrl = new URL(sUrlBuffer.toString());
>>> Image oImage = Toolkit.getDefaultToolkit().getImage(oUrl);
>>> MediaTracker oTracker = new MediaTracker(oFrame);
>>>
>>> oTracker.addImage(oImage, 0);
>>> oTracker.waitForAll();
>>>
>>> BufferedImage oBuffedImage = new
>>> BufferedImage(oImage.getWidth(oFrame), oImage.getHeight(oFrame),
>>> BufferedImage.TYPE_INT_RGB);
>>>
>>> Graphics2D oBiContext = oBuffedImage.createGraphics();
>>> LatLonPoint oOrigin = oProjection.inverse(0, 0);
>>> OMRaster oRaster = new OMRaster(oOrigin.getLatitude(),
>>> oOrigin.getLongitude(), oImage);
>>>
>>> oGraphicList.insertOMGraphicAt(oRaster, 0);
>>> oGraphicList.project(oProjection, true);
>>> oGraphicList.render(oBiContext);
>>>
>>> byte[] byData = oFormatter.formatImage(oBuffedImage);
>>>
>>> ServletOutputStream oOstream = response.getOutputStream();
>>> response.setContentType("image/jpeg");
>>> oOstream.write(byData);
>>> }
>>> catch (Exception e)
>>> {
>>> throw new ServletException(e.getMessage());
>>> }
>>> }
>>>
>>>
>>>
>>
>>
>
>

--
[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 Thu Jul 31 11:40:13 2003

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