I have an image, a shapefile, and a method which can translate an x/y pixel location from the image into a latitude/longitude point or vice versa. I'm trying to use Geotools to render the shapefile on the image, but I can't seem to get it to work.

All of the examples and tutorials I can find use factories to retrieve pre-existing transforms and mappings, but how can I use my custom projection?

Edit: The image is the view from a satellite, which means that it cannot see the entire earth. Is Geotools capable of handling this?

Edit2: I don't think that this can be done easily in GeoTools, I ended up just writing what I needed from scratch.

  • Is this an actual projection or can it be handled as a transform?
    – Clint
    Mar 28, 2012 at 20:47
  • @Clint "Projection" may be a misnomer. It could be done in a transform although I need to be transforming it to the coordinate system of the image. Mar 28, 2012 at 20:57
  • I think that if you provide some more details then you can get this answered. For example it seems that you have an image of a section of the earth. do you have the coordinates of the corners? And do you know the center of the image?
    – Clint
    Mar 29, 2012 at 6:50
  • I believe you have a satellite image and a blank shapefile..and you want to convert some/all pixels from the image to features in the shapefile using geotools..is this correct?
    – vinayan
    Apr 2, 2012 at 12:03

3 Answers 3


I don't understand completely your question, probably due to my limit knowledge about projections, but you can read and transform the features of a shapefile easily: http://docs.geotools.org/stable/userguide/tutorial/geometry/geometrycrs.html#export-reprojected-shapefile

=== UPDATED ===

Here you can find a simple creating a CRS from a WKT expression: docs.geotools.org/latest/userguide/library/referencing/crs.html and docs.geotools.org/latest/userguide/library/main/geometry.html.

That can help you.


If it's a non-affine transformation, then you're going to have trouble with line segments staying straight when they should be curved in the image's space. This is a general problem with transforming vectors, and with sufficiently small line segments, isn't usually too much of a problem.

If you don't know ahead of time what the projection parameters are for the image, or if they cannot be represented by standard map-projection parameters - if the image hasn't been rectified for instance - then you really have one course open to you: manual rasterization. If you're on 3D-accelerated hardware, it would be a fairly simple fragment shader to map from one space to another, given that you have the function already. However, if you're working on a headless server or similar, you'll need to roll your own polygon rasterizer, transforming points from one space to the other as you go. This isn't too difficult, and much has been written on it in the past, but it is mostly just time-consuming to write.

A simple, if not very efficient, method would be to scan over each pixel in the satellite image, transform the coordinate into your polygons' space, and do a simple inside/outside test of that point on your polygons. If it's inside, then colour your pixel appropriately. Lines are a bit harder with this method, but you essentially have to measre the cross-track error of your point against the line, and colour it if it is within some distance, but this won't be very pretty. You could use an alpha value based on the CTE, which would smooth the lines out somewhat, but it's hardly the cutting edge of anti-aliasing.

  • Manual rasterization is what I ended up doing. Apr 2, 2012 at 19:30

Although this not exactly for Geotools, this should work.(actually this is for GeoServer). This explains how to define a custom projection, edit the EPSG.sql file, which is used to create the cached EPSG database.:

Manually editing the CRS database

Another option is creating your own PROJ4 expression for your custom projection. You can use http://spatialreference.org/ for this.

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.