0

I need to reproject a point from EPSG:4326 to EPSG:2193.I tried to achieve that doing the following:

Updated: Here is the little Angular2 service that I wrote: It takes a coordinate and and tries to reproject it. Afterwards it returns a filter string.

import {Injectable} from '@angular/core';
import {OlService} from './ol.service';

@Injectable()
export class OlFilterService {

constructor(private olService: OlService) {

}

pip = (coords: [number,number]) => {
    let ol = this.olService.get();



    let reprojectedCoords = ol.proj.transform(coords, 'EPSG:4326', 'EPSG:2193');


    let filter = 'Intersects(the_geom,POINT(' + reprojectedCoords + '))';


    return filter;


}

}

This code silently fails on me. I just don't get anything or 'false' back. Is it simply not possible or am I missing something?

  • Can you post your complete code so we can see where exactly the problem ? – Shiko Dec 1 '16 at 2:57
  • Hi Shiko Done that. It is a little service within an Angular2 project. – Uwe Dec 1 '16 at 3:11
  • Did you check the ol object if is null, also the return of 'reprojectedCoords' is it null or false ? Also verify that you are getting the coordinates correct. – Shiko Dec 1 '16 at 3:15
  • Hi Shiko Thanks for your answers: Yes - the ol object is properly created. Yes - the coordinates are also correct. To test that I changed the project statement to reporject into 3857, which is working fine – Uwe Dec 1 '16 at 3:31
  • 1
    May be ol doesn't recognize your projection. Try to add the projection definition for 'EPSG:2193' using proj4 – itsyahani Dec 1 '16 at 8:16
1

itsyahani is right, openlayers doesn't recognise EPSG:2193 out of the box. You'll need to add the projection in your code.

First include openlayers and proj.js:

<script src="https://openlayers.org/en/v4.4.2/build/ol.js" type="text/javascript"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.4.4/proj4.js"></script>

Now in your script define the projection and its extents:

proj4.defs("EPSG:2193","+proj=tmerc +lat_0=0 +lon_0=173 +k=0.9996 +x_0=1600000 +y_0=10000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +axis=neu");
var projection = ol.proj.get('EPSG:2193');
projection.setExtent([827933.23, 3729820.29, 3195373.59, 7039943.58]);
ol.proj.addProjection(projection);

You can now use EPSG:2193 like any other projection.

Your Answer

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

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