Re: [Geotools-gt2-users] generailisation

2019-03-20 Thread Ian Turton
I think this might depend on how you set up your output datastore, or what
sort it is - I've attached my code which I've been using on Shapefiles with
no issues (on master)

Ian

On Tue, 19 Mar 2019 at 13:50,  wrote:

> Hi Ian,
>
> This is how I use the generalizer:
>
> *while* (fit.hasNext()) {
>
>SimpleFeature inFeature = fit.next();
>
>MultiPolygon polygon = (MultiPolygon) inFeature.getDefaultGeometry();
>
> *  if* (polygon!= *null* && polygon.isSimple()) {
>
>   Coordinate[] coords = polygon.getCoordinates();
>
>   System.*out*.println("ant coords before = " + coords.length);
>
>   // Genarelize all polygons with more then 5 points
>
> *  if* (coords.length > 5) {
>
>  DouglasPeuckerSimplifier simplifier = *new*
> DouglasPeuckerSimplifier(polygon);
>
>  simplifier.setDistanceTolerance(10);
>
>  simplifier.setEnsureValid(*false*);
>
>  Geometry out =  simplifier.getResultGeometry();
>
>  coords = out.getCoordinates();
>
>  System.*out*.println("ant coords after = " + coords.length);
>
>  }
>
>  // make all coordinates (x,y,0)
>
>  Coordinate[] coords2 = *new* Coordinate[coords.length];
>
> * for*(*int* i = 0; i < coords.length; i++){
>
> Coordinate c = *new* Coordinate(coords[i].x, coords[i].y, 0);
>
> coords2[i] = c;
>
>  }
>
>  // Do your thing here with the coordinates, but first make sure that
> you create lines correct.
>
>  // Just make the polygon to a line string
>
>  // coords2 = CreateCenterLineFromCooordinates(coords2);
>
>  LineString line = gFactory.createLineString(coords2);
>
>  SimpleFeature feature = writer.next();
>
>  List l = inFeature.getAttributes();
>
> * for* (*int* i = 1; i < l.size(); i++) {
>
> // copy all attributes but the first geometry
>
> feature.setAttribute(i, l.get(i));
>
>  }
>
>  feature.setDefaultGeometry(line);
>
>  writer.write();
>
>   }
>
> }
>
> writer.close();
>
> tx.commit();
>
> tx.close();
>
> fit.close();
>
> }
>
>
>
> I can see that the coordinates from the generalizer seems correct
> (x,y,n/a) in the debugger.
>
> I have tried to change the coordinates, so that all has (x,y,0), even
> those polygons who are not generalized.
>
> Then I create a line instead of a polygon.
>
> When I look in PostGis the objects that are generalized has no geometry =
> null, but not the others. It must be something that I’m doing wrong or is
> it something I miss?
>
> I have pointed out GeooTools 20.2 in my pom file.
>
>
>
> Kind regards,
>
> Paul
>
>
>
> *Från:* Ian Turton [mailto:ijtur...@gmail.com]
> *Skickat:* den 15 mars 2019 18:15
> *Till:* Malm, Paul (Operations AIM)
> *Kopia:* geotools-users
> *Ämne:* Re: [Geotools-gt2-users] generailisation
>
>
>
> How are you getting the coordinates out? Most output formats will ignore Z
> if it is not set.
>
>
>
> Ian
>
>
>
> On Fri, 15 Mar 2019 at 15:08,  wrote:
>
> Hi Ian!
>
> Thanks, it worked. But there is one problem.
>
> The unchanged objects has (x,y) coordinates and I’m getting (x,y,n/a)
> coordinates for the changed object.
>
> ArcGis does not seem to be able to have this(x,y,z) coordinates or mixed
> coordinate types. The changed objects
>
> has the correct values of x,y but does not show in ArcGis.
>
> Does anyone have any suggestions?
>
> Kind regards,
>
> Paul
>
>
>
> *Från:* Ian Turton [mailto:ijtur...@gmail.com]
> *Skickat:* den 15 mars 2019 09:49
> *Till:* Malm, Paul (Operations AIM)
> *Kopia:* geotools-users
> *Ämne:* Re: [Geotools-gt2-users] generailisation
>
>
>
> You should be able to use a DouglasPeuckerSimplifier to achieve this.
> Something like:
>
>
>
> DouglasPeuckerSimplifier simplifier = new DouglasPeuckerSimplifier(in);
>
> simplifier.setDistanceTolerance(tolerance);
>
> Geometry out =  simplifier.getResultGeometry();
>
>
>
> would do it.
>
>
>
> JTS also provides a TopologyPresersevingSimplifier and a
> LineSegmentSimplifier that would also handle your case.
>
>
>
> Ian
>
>
>
> On Fri, 15 Mar 2019 at 06:32,  wrote:
>
> Hi,
>
> I wonder if there is a generalize function using angles.
>
> I have polygons almost like a rectangle/romb. 90 percent has only five
> vertices, but some have more. The extra vertices is om the sides (the
> straight lines).
>
> I would like to remove those vertices and thought that there perhaps is a
> method using a max angle to find the extra vertices.
>
> Kind regards,
>
> Paul
>
> ___
> GeoTools-GT2-Users mailing list
> GeoTools-GT2-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>
>
>
> --
>
> Ian Turton
>
>
>
>
> --
>
> Ian Turton
>


-- 
Ian Turton
package com.ianturton.cookbook.operations;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

import org.geotools.data.DataUtilities;
import 

[Geotools-gt2-users] Removing lines from a shape file which has an identical geometry in another shape file

2019-03-20 Thread paul.malm
Hi,
I would like to use GeoTools to delete line objects in a shape file that has an 
identical geometry in another shape file.
Is there someone who can point me in the right direction, how to do this?
I'm learning to use GeoTools, and it seems great!

Thanks,
Paul
___
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users