Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prj in options does not work #115

Open
adikte opened this issue Nov 16, 2023 · 7 comments
Open

Prj in options does not work #115

adikte opened this issue Nov 16, 2023 · 7 comments

Comments

@adikte
Copy link

adikte commented Nov 16, 2023

Hello i am trying to make a shp file with a custom PROJCS in the file.prj but nothing seem to work. I am using [email protected]. I tried using both shpwrite.zip and shpwrite.download with no results. Whatever i put in the options object i get the standard prj (WGS84), everything else work fine thought.

`function table_to_shapefile(source, geomType, file_name) {

const options = {
    folder: file_name,
    filename:  file_name,
    outputType: "blob",
    compression: "DEFLATE",
    prj: 'PROJCS["RGF93_v1_Lambert-93",GEOGCS["GCS_RGF93_v1",DATUM["D_Reseau_Geodesique_Francais_1993_v1",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",700000.0],PARAMETER["False_Northing",6600000.0],PARAMETER["Central_Meridian",3.0],PARAMETER["Standard_Parallel_1",49.0],PARAMETER["Standard_Parallel_2",44.0],PARAMETER["Latitude_Of_Origin",46.5],UNIT["Meter",1.0]]',
    types: {
        point: file_name,
        polygon: file_name,
        polyline: file_name,
      }
};

// transform data to geojson
const geojson = transform_geom_geojson(source, geomType);
//shpwrite.download(geojson, options)

shpwrite.zip(geojson, options)
    .then((res_zip) => {
        const anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(res_zip);
        anchor.download = file_name + '.zip';
        document.body.appendChild(anchor);
        anchor.click();
        document.body.removeChild(anchor);
    })
    .catch((error) => {
        console.error("Erreur lors de la création du fichier ZIP", error);
    });

}`

@tandyx
Copy link

tandyx commented Jun 10, 2024

Hi @adikte,

Having this issue as well, have you (or anyone else) found a solution? I remember this worked on an older version.

Thanks all

edit:

it seems like this line (taken from shpwrite.js in the npm package) was removed

var prj = (options && options.prj) ? options.prj : defaultPrj;

another edit:

building from source w/ npm run make results in the line (2909) appearing there; don't know why that's happening

another edit:

this solution is ugly, but I went into node_modules/@mapbox/shp-write/shpwrite.js and changed line 4188 from

zipTarget.file(fileName + ".prj", prj);

to:

zipTarget.file(fileName + ".prj", options?.prj || prj);

@sheindel
Copy link
Contributor

@adikte or @johan-cho

Can you confirm in your node_modules which version you have installed? Did you note the change from the original package shp-write to the new package @mapbox/shp-write?

@sheindel
Copy link
Contributor

Here is what I have in my node_modules folder after installing @mapbox/shp-write in a fresh project
image

@sheindel
Copy link
Contributor

I also looked at a recent project I set up that uses @mapbox/shp-write with vite and pnpm as my primary build tooling and digging into the output and minified JS, I can still see this line
image

@tandyx
Copy link

tandyx commented Jun 11, 2024

this is what i see setup when I download from npm:
image

edit:
similar to pnpm

@sheindel
Copy link
Contributor

Oh interesting!

I'm not sure why that is happening. I do see that in my node_modules as well. However, when I debug through my use of shpwrite.zip(...) inside the packaged module with my current application, I can confirm that it does have this line in it. This should be because when you import it is actually looking at the dist/index.js file in the package repo, which simply looks at various files in src/*. The shpwrite.js is for browser specific use when including it as a traditional JS script (e.g. <script src='shpwrite.js'></script>) and actually is not needed but I believe it gets automatically built when the library is installed because the make command is called.

image

@tandyx
Copy link

tandyx commented Jun 11, 2024

I think both @adikte were using the shpwrite.js file as a traditional browser script. yeah, it's interesting that I see the line with npm run make locally, but it doesn't exist in the unpkg or npm links.

I'm sure whenever you update the package it'll probably fix itself, but for now we have a solution and I'm satisfied.

Thanks for all your work on this package! It's really made my life easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants