Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Is this an actual projection or can it be handled as a transform? – Clint Mar 28 '12 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. – Jordan Bentley Mar 28 '12 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 '12 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 this correct? – vinayan Apr 2 '12 at 12:03

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.

share|improve this answer
Manual rasterization is what I ended up doing. – Jordan Bentley Apr 2 '12 at 19:30

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:

=== UPDATED ===

Here you can find a simple creating a CRS from a WKT expression: and

That can help you.

share|improve this answer
That only shows how to transform a shapefile using predefined projections and coordinate reference systems. My problem is that I can't get my custom format from the factories. – Jordan Bentley Mar 26 '12 at 14:54
You can create your own projection file if you know about your projection. Check this:… – EricSonaron Mar 26 '12 at 15:01
There is information that isn't known until runtime – Jordan Bentley Mar 26 '12 at 16:34
No problem, you can create a like PROJ4 expression and parse it at runtime. Check… the 'createFromWKT' method. – EricSonaron Mar 26 '12 at 20:43
Assuming I'm understanding this correctly, I can't make a PROJ4 expression for a custom projection. – Jordan Bentley Mar 26 '12 at 21:11

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 for this.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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