Hi,

I made a program to write some features to a mysql database, following the example at http://geotools.codehaus.org/How+to+add+features+data+into+MySQL. I get an error like the following when I try to add a FeatureReader to a FeatureStore: NoSuchMethodError: org.geotools.filter.FilterCapabilities.addType(J)V.

I send the code and the sql script that generates the tables, once this is not supported (yet?).

Can someone help me?

Thanks in advance,
Rui Lopes

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

# Host: localhost
# Database: mater
# Table: 'patches'
# 
CREATE TABLE patches (
  width int(8) default NULL,
  location point default NULL,
  elevation int(8) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE roads ( 
        width int(8) default NULL,
        geom linestring default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

package MATer.mysql;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

import org.geotools.data.DataUtilities;
import org.geotools.data.FeatureReader;
import org.geotools.data.FeatureStore;
import org.geotools.data.mysql.*;
import org.geotools.factory.FactoryConfigurationError;
import org.geotools.feature.AttributeType;
import org.geotools.feature.AttributeTypeFactory;
import org.geotools.feature.Feature;
import org.geotools.feature.FeatureType;
import org.geotools.feature.FeatureTypeFactory;
import org.geotools.feature.GeometryAttributeType;
import org.geotools.feature.IllegalAttributeException;
import org.geotools.feature.SchemaException;
import org.geotools.graph.util.geom.Coordinate2D;
import org.opengis.spatialschema.geometry.geometry.LineString;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.io.WKBReader;
import com.vividsolutions.jts.io.WKTReader;


import MATer.FileManager;
import MATer.Patch;

public class Main  implements MATer.Definitions {

	private Patch[][] patches;
	private MySQLDataStore datastore;
	
	Main(){
		
	}
	
	public void init(){
		patches = new Patch[_DEFAULT_WORLD_WIDTH][_DEFAULT_WORLD_HEIGHT];
		for( int i = 0 ; i < patches.length; i++ )
			for( int j = 0 ; j < patches[0].length; j++)
				patches[i][j]= new Patch( i, j , null);
		

		loadGISData( patches );
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Main main = new Main();
		main.createDataStore();
		main.init();
		main.populateDB();
	}
	
	private void populateDB() {
		AttributeType pWidth = AttributeTypeFactory.newAttributeType("width", Integer.class);
		GeometryAttributeType pLoc =
		      (GeometryAttributeType)AttributeTypeFactory.newAttributeType("location", Point.class);
		AttributeType pElevation = AttributeTypeFactory.newAttributeType("elevation", Integer.class);
		try {
			FeatureType ftPatch = FeatureTypeFactory.newFeatureType(
					new AttributeType[] { pWidth, pLoc, pElevation  }, "patches");
			
//			 intances
			ArrayList<Feature> altemp = new ArrayList<Feature>();
			Feature tempF = null;
			GeometryFactory gf = new GeometryFactory();
			Point locGeom = null;
			for(int i = 0 ; i < patches.length; i++)
				for(int j = 0 ; j < patches[0].length; j++){
					
					locGeom = gf.createPoint( new Coordinate( patches[i][j].getX(), patches[i][j].getY()) );
					tempF = ftPatch.create(new Object[] { 1 ,locGeom, patches[i][j].getElevation() },
					"Patch-"+i+"-"+j); 
					altemp.add(tempF);					
				}
			
			FeatureStore fsPatches = (FeatureStore)(datastore.getFeatureSource("patches"));			
			FeatureReader aReader = DataUtilities.reader( altemp );			
			fsPatches.addFeatures(aReader);
			
		} catch (FactoryConfigurationError e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SchemaException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAttributeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		
		
		
	}

	private void createDataStore() {

		MySQLDataStoreFactory factory = new MySQLDataStoreFactory();
		Map params = new HashMap();
		params.put( "database", "mater" );
		params.put( "dbtype", "mysql");
		params.put( "host", "localhost");
		params.put( "port", "3306");
		params.put( "user", "ruya");
		params.put( "passwd", "rui8299");
		
		try {
			this.datastore = (MySQLDataStore) factory.createDataStore( params );
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		System.out.println("DataStore created!");
	}
	
	private void loadGISData( Patch[][] patches ) {		
		loadTopo( patches, _TOPO_PATH );
		loadHidro( patches, _HIDRO_PATH );
		/*
		for( int i = 0 ; i < getWorldXSize(); i++ ){
			for( int j = 0 ; j < getWorldYSize(); j++ ){
				//patches[i][j].setAgentCapacity();
				space.putObjectAt( i , j , patches[i][j] );
			}
		}
		*/
	}

	private void loadTopo( Patch[][] patches, String fpath ){				
		FileManager fm = new FileManager( fpath );
		int line_y = 0, counter_x = 0;

		String line = null;
		while( ( line = fm.readLine() ) != null ){
			StringTokenizer tokens = new StringTokenizer( line );
			counter_x = 0;
			while( tokens.hasMoreTokens() ){
				try {
					int a = Integer.parseInt( tokens.nextToken() );
					patches[counter_x][line_y].setElevation( a );
					//patches[counter_x][line_y].setAgentCapacity();
					//meanElevation += a;
				}
				catch ( java.lang.IndexOutOfBoundsException e) {
					System.out.println("deu BODE qd ia no y = "+line_y+" e x = "+counter_x);
				}
				counter_x++;
			}	
			line_y++;
		}
		//meanElevation = meanElevation / (getWorldXSize() * getWorldYSize());
	}

	private void loadHidro( Patch[][] patches, String fpath ){				
		FileManager fm = new FileManager( fpath );
		int line_y = 0, counter_x = 0;

		String line = null;
		while( ( line = fm.readLine() ) != null ){
			StringTokenizer tokens = new StringTokenizer( line );
			counter_x = 0;
			while( tokens.hasMoreTokens() ){
				try {
					int a = Integer.parseInt( tokens.nextToken() );
					patches[counter_x][line_y].setWater( ( a == 1 )? true : false );
					//patches[counter_x][line_y].setAgentCapacity();
				}
				catch ( java.lang.IndexOutOfBoundsException e) {
					System.out.println("deu BODE qd ia no y = "+line_y+" e x = "+counter_x);
				}
				counter_x++;
			}	
			line_y++;
		}
	}
}

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to