***************************************************************
**     Gabriella Turek               [EMAIL PROTECTED]      **
** National Institute of Water & Atmospheric Research (NIWA) **
** PO Box 8602 Christchurch New Zealand    +64-3-343-8067    **
***************************************************************


>>>Jody Garnett <[EMAIL PROTECTED]> 12/11/07 1:09 pm >>> 
>Okay you are trying to do a join; the only way to do that is with a 
>loop. In short your code is insane - since there is no service or api that can 
>accept that 
>filter; ie there is no way to do the join. 



That's what I thought...
So here's the original code (the one that worked) in all its gory detail,
with the addition of the Collection_MaxFunction usage.
It deals with different types pair of shape type files, but so far I have not 
been able to
get dwithin to work, ugh.
I am not sure what a
visitor would buy me, on the other hand, I am not sure how to implement it 
either.
You can use any of this code for the web if it helps
gaby


          //B shapefile
          EnhancedMapLayer hazard = (EnhancedMapLayer)context.getLayer(1);
          FeatureSource fsh = hazard.getFeatureSource();
          int hazardType = hazard.getShapeType().id;

          //A shapefile
          EnhancedMapLayer asset = (EnhancedMapLayer)context.getLayer(2);
          FeatureSource fsa = asset.getFeatureSource();
          int assetType = asset.getShapeType().id;
          FeatureCollection fca = fsa.getFeatures();
          FeatureIterator fia  = fca.features();  

          // create a filter
          FilterFactory filterFactory = 
FilterFactoryFinder.createFilterFactory();
          // look up geometry attribute name
          String geometryName = fsh.getSchema().getDefaultGeometry().getName();
          // Create the attribute expression
          AttributeExpression geometryExpression = 
filterFactory.createAttributeExpression(geometryName);
          GeometryFactory geometryFactory = new GeometryFactory();
          GeometryFilter geoFilter = null;
          AttributeExpression velExpression = null;
          
          if (hazardType == 5 && (assetType == 8 || assetType == 5 || assetType 
== 3))
          {
            geoFilter = 
filterFactory.createGeometryFilter(FilterType.GEOMETRY_INTERSECTS);             
        
            geoFilter.addLeftGeometry(geometryExpression);
            velExpression = filterFactory.createAttributeExpression("GRIDCODE");
          } else if (hazardType == 1 && assetType == 1) {
            geoFilter = 
filterFactory.createGeometryFilter(FilterType.GEOMETRY_DWITHIN);                
        
            velExpression = filterFactory.createAttributeExpression("Z1000_YR");
          }

          Vector vels = new Vector(fca.size());
          while (fia.hasNext()) 
          {
            Feature ffa = fia.next();
            Object aasset = ffa.getAttribute("the_geom");
            LiteralExpression expression = 
filterFactory.createLiteralExpression();
            expression.setLiteral(aasset);
            if (hazardType == 5 && (assetType == 8 || assetType == 5 || 
assetType == 3))
            {
              geoFilter.addRightGeometry(expression);
              FeatureCollection fch = fsh.getFeatures(geoFilter);
              CalcResult result =       
Collection_MaxFunction.calculateMax(fch, velExpression);
              long max = (Long)result.getValue();
              vels.add(max);
            } else if (hazardType == 1 && assetType == 1) {
              DWithin filter = filterFactory.dwithin(geometryExpression, 
expression, 10, "degree" );
              FeatureCollection fch = fsh.getFeatures((Filter)filter);
              CalcResult result =       
Collection_MaxFunction.calculateMax(fch, velExpression);
              double max = (Double)result.getValue();
              vels.add(max);
            }
         }
 


-------------------------------------------------------------------------
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-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to