Could I ask you to move conversation open to udig-...@locationtech.org -
this email list should be shut off by now :)


On Wed, Aug 14, 2013 at 4:40 PM, Amit Shukla <ami...@indictranstech.com>wrote:

> Hello there ,
>
> I am working udig 1.3.2 . I have created shapefile using resultset and
> render.
> by refering this tutorial geotool csv to 
> shp<http://docs.geotools.org/stable/tutorials/feature/csv2shp.html>
> .
>
> I have added layer programatically it render successfully but when i
> restart the udig then error displays at bottom as "*There was no renderer
> found capable of rendering this layer*"
>
> I dont no what i am missing here is my code
> /*create shapefile */
> public void writeShapeFile(ResultSet rs, File outputShapeFile) throws
> SQLException,
>             SchemaException, ParseException, IOException {
>
>     System.out.println("file path :->>>>> "+outputShapeFile);
>
>         final String geomColumnName = "the_geom";
>         final int srid = 32644;
>         CoordinateReferenceSystem crs = null;
>         try {
>             crs = CRS.decode("EPSG:32644");
>         } catch (NoSuchAuthorityCodeException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (FactoryException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }
>         String geomType = "Point";
>
>         ResultSetMetaData metaData = rs.getMetaData();
>         int numberOfColumns = metaData.getColumnCount();
>         ArrayList<String> columnNames = new ArrayList<String>();
>         ArrayList<String> columnTypes = new ArrayList<String>();
>         for (int i = 0; i < numberOfColumns; i++) {
>             if (metaData.getColumnLabel(i +
> 1).equalsIgnoreCase("the_geom")) {
>                 columnNames.add(0, metaData.getColumnLabel(i + 1));
>                 columnTypes.add(0, metaData.getColumnTypeName(i + 1));
>             } else {
>                 columnNames.add(metaData.getColumnLabel(i + 1));
>                 columnTypes.add(metaData.getColumnTypeName(i + 1));
>
>             }
>         }
>
>         StringBuilder stringBuilder = new StringBuilder();
>
>         stringBuilder.append("location:" + geomType + ":srid=" + srid +
> ",");
>
>         /*
>          * Iterate incoming List. Contains column name and its data type
>          */
>         // for (Iterator<String> iterator = columnNames.iterator();
> iterator.hasNext();) {
>         for (int i = 0; i < columnNames.size(); i++) {
>             String columnName = columnNames.get(i);
>             String columnType = columnTypes.get(i);
>             if (columnName.equalsIgnoreCase(geomColumnName)) {
>                 continue;
>             }
>
>             if (i < columnNames.size() - 1) {
>                     stringBuilder.append(columnName + ":" + "String");
>                     stringBuilder.append(",");
>             } else {
>                     stringBuilder.append(columnName + ":" + "String");
>             }
>
>         }
>
>         String columns = stringBuilder.toString();
>         final SimpleFeatureType TYPE =
> DataUtilities.createType("Location", columns);
>
>         List<SimpleFeature> features = new ArrayList<SimpleFeature>();
>         SimpleFeatureBuilder featureBuilder = new
> SimpleFeatureBuilder(TYPE);
>
>         Geometry geom = null;
>         String wkb = null;
>         MultiPolygon multipolygon = null;
>         MultiLineString multiLineString = null;
>         MultiPoint multipoint = null;
>         while (rs.next()) {
>             try {
>                 for (Iterator<String> iterator = columnNames.iterator();
> iterator.hasNext();) {
>                     String columnName = (String) iterator.next();
>
>                     if (columnName.equalsIgnoreCase(geomColumnName)) {
>                         wkb = rs.getString(columnName);
>                         byte[] aux = WKBReader.hexToBytes(wkb);
>                         geom = new WKBReader().read(aux);
>                             Point[] pointArray = new
> Point[geom.getNumGeometries()];
>                             for (int i = 0; i < geom.getNumGeometries();
> i++) {
>                                 Geometry partGeometry =
> geom.getGeometryN(i);
>                                 pointArray[i] = new Point(new
> CoordinateArraySequence(
>                                         partGeometry.getCoordinates()),
> new GeometryFactory(
>                                         new PrecisionModel(), srid));
>                             }
>                             multipoint = new MultiPoint(pointArray, new
> GeometryFactory(
>                                     new PrecisionModel(), srid));
>                             featureBuilder.add(multipoint);
>                     } else {
>                         featureBuilder.add(rs.getString(columnName));
>                     }
>                 }
>
>                 SimpleFeature simpleFeature =
> featureBuilder.buildFeature(null);
>                 features.add(simpleFeature);
>
>             } finally {
>                 geom = null;
>                 wkb = null;
>                 multipolygon = null;
>                 multiLineString = null;
>                 multipoint = null;
>             }
>         }
>
>         ShapefileDataStoreFactory dataStoreFactory = new
> ShapefileDataStoreFactory();
>
>         Map<String, Serializable> params = new HashMap<String,
> Serializable>();
>         params.put("url", outputShapeFile.toURI().toURL());
>         params.put("create spatial index", Boolean.TRUE);
>
>         ShapefileDataStore shapefileDataStore = (ShapefileDataStore)
> dataStoreFactory
>                 .createNewDataStore(params);
>         //System.out.println("feature type" + TYPE);
>         shapefileDataStore.createSchema(TYPE);
>         // shapefileDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
>         shapefileDataStore.forceSchemaCRS(crs);
>
>         Transaction transaction = new DefaultTransaction("create");
>         String typeName = shapefileDataStore.getTypeNames()[0];
>         SimpleFeatureSource featureSource =
> shapefileDataStore.getFeatureSource(typeName);
>
>         if (featureSource instanceof SimpleFeatureStore) {
>             SimpleFeatureStore featureStore = (SimpleFeatureStore)
> featureSource;
>
>             SimpleFeatureCollection collection = new
> ListFeatureCollection(TYPE, features);
>             featureStore.setTransaction(transaction);
>
>             featureStore.addFeatures(collection);
>             transaction.commit();
>         }
>
>         transaction.close();
>     }
>
> /*loading layer programatically*/
> URL fileUrl = null;
> try {
> fileUrl = file.toURI().toURL();
>     } catch (MalformedURLException e1) {
> e1.printStackTrace();
>     }
> CatalogPlugin cp = CatalogPlugin.getDefault();
> IServiceFactory sf = cp.getServiceFactory();
> List<IService> services = sf.createService(fileUrl);
> List<IGeoResource> resources = new ArrayList<IGeoResource>();
> for( IService service : services ) {
> List<? extends IGeoResource> geoResource = null;
> try {
> geoResource = service.resources(new NullProgressMonitor());
> }catch (IOException e) {
>
> e.printStackTrace();
> }
> if (geoResource != null) {
> for( IGeoResource iGeoResource : geoResource ) {
> resources.add(iGeoResource);
> }
> }
> }
> ApplicationGIS.addLayersToMap(ApplicationGIS.getActiveMap(), resources,
> -1, null, true);
>
> It works fine but when restart the application error occured for that
> layer.
> Can anyone help me to solve this issue ???
>
> Thanks
> Amit
>
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel
>
>
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel

Reply via email to