I have county shapefile and school district shapefile.

Once each school district file is overlay on county shapefile I would like to know how much percentage of area of school district file covered by each county shapefile.

Any idea how I can use GeoTools Java library or any other Java library to do that?

1 Answer 1


The basic algorithm for this is:

  • read in districts
  • read in counties
  • foreach district in districts
    • split district by counties
    • calculate area as % of original

GeoTools (and JTS) are able to take care of all of these steps for you, the quickstart tutorial will have shown you how to read in your shapefiles. The query tutorial will get you up to speed on FeatureCollections and filters.

To split a feature's geometry you will need to use JTS which GeoTools wraps for you as Geometry Operations.

Your inner loop will look something like (untested code):

Filter filter = CQL.toFilter("INTERSECTS(the_geom,"+district.toWKT()+")");
SimpleFeatureCollection features = counties.getFeatures(filter);
SimpleFeatureIterator it = features.features();
  SimpleFeature next = (SimpleFeature)it.next();
  Geometry overlap =  district.intersection(next.getDefaultGeometry());
  double area = overlap.getArea();

I've knocked up a full example too.

  • Thanks. I am using latest version of GEO Tools Which is 13.1.I m getting error Error while parsing JAI registry file "file:geotools-13.2/imageio-ext-imagereadmt-1.1.11.jar!/META-INF/registryFile.jai" : Error in registry file at line number #29. A descriptor is already registered against the name "ImageReadMT" under registry mode "rendered" Exception in thread "main" java.lang.NullPointerException at sg.gis.schooldistict.features.Overlaps.overlap(Overlaps.java:67) at sg.gis.schooldistict.features.Overlaps.main(Overlaps.java:34). Should i be using another version of GEO Tools?
    – ajd
    Aug 14, 2015 at 18:48
  • I don't think the first issue is related to the second one. See what line 67 is using
    – Ian Turton
    Aug 14, 2015 at 18:58
  • I used the exact same code u provided which is very cool. Error i see it is System.out.println("100.00% of "+feature.getAttribute("NAME")+" is in "+ f2.getAttribute("NAME")); One thing is this is my first GIS related program so may be i m giving wrong input. I am using tl_2010_01_tract10/tl_2010_01_tract10.shp from census website. It has few other files like dbf,prj etc. Should i be using ".shp" file as input?
    – ajd
    Aug 14, 2015 at 19:13
  • Do you have an attribute called NAME? You will need to modify the attribute names to match your data or delete those lines
    – Ian Turton
    Aug 15, 2015 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.