Streaming Renderer and ShapefileRenderer can only draw one kind of Geometry at 
a time
-------------------------------------------------------------------------------------

                 Key: GEOT-1611
                 URL: http://jira.codehaus.org/browse/GEOT-1611
             Project: GeoTools
          Issue Type: Bug
    Affects Versions: 2.5-M0, 2.3.5, 2.4-RC0
            Reporter: Jody Garnett
            Assignee: Jody Garnett


If you are using ShapefileRenderer or Streaming renderer to draw several layers 
you will run into problems when the layers are of different types.

Here is the email from Enam:
{panel}
I found a critical bug in ShapefileRenderer that comes with geotools 2.3.5.

When using multiple layers with different geometry type, only the first layer 
is shown. For example, if one shapefile contains polygons while the other 
shapefile contains points and you have two layers - one for each shapefile. 
Second layer's feature cannot be drawn because of the following:
{code}
        private Object getGeom(GeometryAttributeType defaultGeometry) {
                if (defaultGeom == null) {
                        if 
(MultiPolygon.class.isAssignableFrom(defaultGeometry.getType())) {
                                defaultGeom = MULTI_POLYGON_GEOM;
                        } else if 
(MultiLineString.class.isAssignableFrom(defaultGeometry
                                        .getType())) {
                                defaultGeom = MULTI_LINE_GEOM;
                        } else if 
(Point.class.isAssignableFrom(defaultGeometry.getType())) {
                                defaultGeom = POINT_GEOM;
                        } else if 
(MultiPoint.class.isAssignableFrom(defaultGeometry
                                        .getType())) {
                                defaultGeom = MULTI_POINT_GEOM;
                        }
                }
                return defaultGeom;
        }
{code}

defaultGeom is an instance variable. There are two problems here:

1) defaultGeom is private and only accessed in this method. This should
rather be a local variable.

2) default geometry may be different for each layer and, therefore, cannot
assume that setting it once is enough. if defaultGeom is not set based on
the defaultGeometry passed to getGeom() method, we will get a class cast
exception when we do

                        values[length - 1] =
getGeom(type.getDefaultGeometry());
                        return type.create(values, id); //LINE 726

In order to make all the layers work properly, the getGeom method should be:
{code}
        private Object getGeom(GeometryAttributeType defaultGeometry) {
                Object defaultGeom; // remove the instance variable and make it 
global
                        if 
(MultiPolygon.class.isAssignableFrom(defaultGeometry.getType())) {
                                defaultGeom = MULTI_POLYGON_GEOM;
                        } else if 
(MultiLineString.class.isAssignableFrom(defaultGeometry
                                        .getType())) {
                                defaultGeom = MULTI_LINE_GEOM;
                        } else if 
(Point.class.isAssignableFrom(defaultGeometry.getType())) {
                                defaultGeom = POINT_GEOM;
                        } else if 
(MultiPoint.class.isAssignableFrom(defaultGeometry
                                        .getType())) {
                                defaultGeom = MULTI_POINT_GEOM;
                        }
                return defaultGeom;
        }
{code}

I removed the check if defaultGeom == null and made defaultGeom a local 
variable. Without this fix, multiple layers with different geometry type will 
not work.
{panel}


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to