On Sun, May 29, 2011 at 2:16 AM, Jiri Novak <[email protected]> wrote:
> Based on pieces of advice I found in other threads of this email list I
> managed to export to PostGIS without any problem. Nevertheless, when I
> change my dependencies back to oracle libraries, I manage to get exported
> all of the attributes data, but the_geom collumn which remains null. And
> there is still the warning causing all the troubles:
>
> May 28, 2011 9:02:36 PM org.geotools.jdbc.JDBCDataStore getMapping
> WARNING: No mapping for com.vividsolutions.jts.geom.Point
>
> Am I missing some additional jar dependency? It seems to me that there is
> some problem with OracleDialect class inicialization, but I have no clue
> where and why :(
Oracle forces all the attributes to uppercase, you have to compensate for that
when doing the copy.
The attached class did work for me in the past, though it may need to be
updated a bit to follow the last api changes.
Generally speaking you cannot pretend the schema created in the target
store to follow the structure you asked for, depending on the target abilities
there may be changes in the names, types and position of the attributes.
Oracle cannot have lowercase attributes, shapefile has just one geometry,
it's the first attribute as it's called "the_geom", SDE will prefix the type
name with some schema bit and so on.
Cheers
Andrea
--
-------------------------------------------------------
Ing. Andrea Aime
GeoSolutions S.A.S.
Tech lead
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 962313
http://www.geo-solutions.it
http://geo-solutions.blogspot.com/
http://www.youtube.com/user/GeoSolutionsIT
http://www.linkedin.com/in/andreaaime
http://twitter.com/geowolf
-------------------------------------------------------
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.geotools.data.DataStore;
import org.geotools.data.DataUtilities;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.FeatureStore;
import org.geotools.data.Transaction;
import org.geotools.data.oracle.OracleNGDataStoreFactory;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.feature.FeatureIterator;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.jdbc.JDBCDataStoreFactory;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.filter.Filter;
public class OracleImporter {
public static void main(String[] args) throws IOException {
String path = "/home/aaime/devel/gs2.0.x/data/release/data/shapefiles/states.shp";
ShapefileDataStore shp = new ShapefileDataStore(new File(path).toURL());
Map<Serializable, Object> params = new HashMap<Serializable, Object>();
params.put(JDBCDataStoreFactory.USER.key, "usr");
params.put(JDBCDataStoreFactory.PASSWD.key, "pwd");
params.put(JDBCDataStoreFactory.HOST.key, "localhost");
params.put(JDBCDataStoreFactory.PORT.key, OracleNGDataStoreFactory.PORT.sample);
params.put(JDBCDataStoreFactory.DATABASE.key, "xe");
params.put(JDBCDataStoreFactory.DBTYPE.key, "oracle");
DataStore oracle = new OracleNGDataStoreFactory().createDataStore(params);
if(oracle != null && oracle.getTypeNames() != null)
System.out.println("Oracle connected");
String typeName = shp.getTypeNames()[0].toUpperCase();
if(!Arrays.asList(oracle.getTypeNames()).contains(typeName))
oracle.createSchema(shp.getSchema());
FeatureStore oraStore = (FeatureStore) oracle.getFeatureSource(typeName);
oraStore.removeFeatures(Filter.INCLUDE);
SimpleFeatureType targetSchema = (SimpleFeatureType) oraStore.getSchema();
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(targetSchema);
FeatureIterator fi = shp.getFeatureSource().getFeatures().features();
SimpleFeatureType sourceSchema = shp.getSchema();
Transaction t = new DefaultTransaction();
oraStore.setTransaction(t);
while(fi.hasNext()) {
SimpleFeature source = (SimpleFeature) fi.next();
for(AttributeDescriptor ad : sourceSchema.getAttributeDescriptors()) {
String attribute = ad.getLocalName();
builder.set(attribute.toUpperCase(), source.getAttribute(attribute));
}
oraStore.addFeatures(DataUtilities.collection(builder.buildFeature(null)));
}
t.commit();
t.close();
}
}
------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users