1

I have collections of polygon features. Each point in a polygon has local cooridantes (x y values) and geodetic Coordinates (latitude and longitude in decimal degree) i can easily export the shape file(vector) with xy values using geotools. How can i export the data by including geodetic coordinates. please help me.

Point - X Y values - latitude and longitude

Polygon points have coordinates with (x y values) i have find the latlong values for each point in the shapefile externally by using rubbersheeting method given in http://www.corrmap.com/features/rubber-sheeting_transformation.php now i need to project the lat long values into the shapefile along with x y values of the points.

Polygons [ p1,p2,p3,p4........soon] p1 - (x ,y) already in the shapefile (lat, long) computed externally.

id-->*******x********y***************lon*********lat

79-->(8912.811,1481.9799):(80.205185,13.336138)

80-->(8912.811,1481.9766):(80.205185,13.336108)

93-->(8912.656,1481.9835):(80.2038,13.336171)

140-->(8912.8125,1482.0161):(80.20521,13.336465)

My code for exporting shape file with x and y coordinates and i need to include projection (lat long).

/**
 *  Writes the Shapes in the featureList into the given File
 *
 *  @param theFile Reference to the File
 *  @param featureList The list of features to be written
 *
 *  @return TRUE if successfully written; Else FALSE
 */
public boolean writeShape(File theFile, List featureList) throws Exception
{
    ShapefileDataStoreFactory dSFactory = new ShapefileDataStoreFactory();

    Map params = new HashMap();
    params.put("url", theFile.toURI().toURL());
    params.put("create spatial index", Boolean.TRUE);

    ShapefileDataStore newDataStore =
                 (ShapefileDataStore) dSFactory.createNewDataStore(params);

    newDataStore.createSchema(featureBuilder.getFeatureType());
    newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);

    String typeName = newDataStore.getTypeNames()[0];
    SimpleFeatureSource featureSource =
                                   newDataStore.getFeatureSource(typeName);

    boolean success = false;
    if (featureSource instanceof SimpleFeatureStore)
    {
        SimpleFeatureStore featureStore = (SimpleFeatureStore)featureSource;

        SimpleFeatureCollection collection =
                  new ListFeatureCollection(featureBuilder.getFeatureType(),
                                            featureList);

        Transaction transaction = new DefaultTransaction("create");
        featureStore.setTransaction(transaction);

        try
        {
            featureStore.addFeatures(collection);
            transaction.commit();
            success = true;
        }
        catch (Exception exp)
        {
            if (DEBUG) exp.printStackTrace();
            transaction.rollback();
            success = false;
        }
        finally
        {
            transaction.close();
        }
    }

    if (success) showMessage(sCreated);
    return success;
}

private SimpleFeatureBuilder createFeatureBuilder()
{
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setCRS(DefaultGeographicCRS.WGS84);
    builder.setName(plotName);

    builder.add(sPolygon, Polygon.class);
    builder.length(32).add(plotName, String.class);
    builder.length(32).add(sArea, String.class);

    final SimpleFeatureType featureType = builder.buildFeatureType();
    return new SimpleFeatureBuilder(featureType);
}

public boolean addPolygonFeature(List featureList, Point3D[] thePoints,
                                 String polyId, float area) throws Exception
{
    Polygon aPoly = createPolygon(thePoints);

    if (aPoly == null)
    {
        StringBuffer buf = new StringBuffer();
        buf.append(WError1);
        buf.append(polyId);
        buf.append(WError2);
        String error = buf.toString();

        int opt = GUIBase.showConfirmDialog(error, "Confirm", GUI_YN);
        return (opt == GUIBase.GUI_YES);
    }

    SimpleFeature feature = featureBuilder.buildFeature(null);
    feature.setAttribute(plotName, polyId);
    feature.setAttribute(sPolygon, aPoly);
    feature.setAttribute(sArea, area);
    featureList.add(feature);
    return true;
}

/**
 *  Creates a polygon feature from Array of FMBPoints
 *
 *  @param thePoints Array of Point3Ds
 *
 *  @return Reference to the Polygon object
 */
public static Polygon createPolygon(Point3D[] thePoints)
{
    int count = (thePoints == null) ? 0 : thePoints.length;
    if (count < 1) return null;

    // Store Coordinates of polygon as a LINESTRING.
    StringBuffer buffer = new StringBuffer();
    buffer.append("POLYGON((");

    for (int i=0; i<count; i++)
    {
        buffer.append(thePoints[i].x);
        buffer.append(SPACE);
        buffer.append(thePoints[i].y);
        buffer.append(COMMA);
    }

    String lineString = buffer.toString();
    lineString = lineString.substring(0, lineString.length()-1) + "))";
    if (DEBUG) System.out.println(lineString);

    try
    {
        // Creating the Geometry (Polygon)
        return (Polygon) wktReader.read(lineString);
    }
    catch (Exception excep) { }

    return null;
}
  • can you show us some code? – Ian Turton Oct 13 '14 at 8:17
  • you asked about points but this code is writing a polygon – Ian Turton Oct 13 '14 at 11:55
  • @iant this code is writing a polygon with points but i need to include the point projection (lat long) is that possible. both point XY and projection iam new to geotools please suggest me – Suri Oct 13 '14 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.