Converting Coordinates in plane SVG File to Coordinates in Inkscape

Discuss SVG code, accessible via the XML Editor.
Vipr0
Posts: 5
Joined: Tue Mar 28, 2017 5:00 am

Converting Coordinates in plane SVG File to Coordinates in Inkscape

Postby Vipr0 » Sat Apr 29, 2017 4:36 am

Hello,

like shown in the title, I want to convert the coordinates i get from the plane SVG-File to the coordinates which are shown in Inkscape. I think the reason for the difference, is that the origin of ordinates in Inkscape is the bottom left corner of my sheet, while the origin in SVG is the top left. Is that always the case? Can i just multiply the y-coordinates with -1 and subtract 297? Does this work for any kind of object (rect and path) even when I "paint" outside of the DIN A4 page as long as the format is still DIN A4?

Thank you in advance
Vipr0

chocolade
Posts: 1
Joined: Mon Jun 05, 2017 10:54 pm

Re: Converting Coordinates in plane SVG File to Coordinates in Inkscape

Postby chocolade » Mon Jun 05, 2017 10:55 pm

Hi,

Did you find any solution ? I have the same problem as you, And so far i can't find any solution how to do it.

EddieRich
Posts: 5
Joined: Wed Jun 21, 2017 10:51 pm

Re: Converting Coordinates in plane SVG File to Coordinates in Inkscape

Postby EddieRich » Thu Jun 22, 2017 12:24 am

I am not an expert on SVG, but after working on CAD files for the past 2 years, I have an understanding of graphics systems.
I have been investigating the SVG files for the past few weeks.

If you look at https://www.w3.org/TR/SVG/coords.html the SVG spec, there are different "coordinate spaces" in the SVG file.
The <svg> element has something called a "viewbox".
This viewbox has an X, Y, Width and Height and does appear to have the X,Y at top left on the page.

The Width and height are defined by the page units times page scale (defined in the document properties dialog).
For instance, my page is 6 inches by 6 inches and my scale is 1000 "user units"
So, my viewbox is 0, 0, 6000, 6000.

When I draw a line from the lower left corner (displayed as 0,0) it is stored in the XML as 0, 6000.

So to answer your question, for the Y axis ...
absolute Y coordinate = viewbox height - Yvalue
relative Y coordinate = Yvalue * -1

This is still in user units, to convert both X and Y to actual displayed units, divide by the page scale.

Inkscape appears to have some problems with rounding errors (my actual path string is d="m 0,6000.0002 1000,-1000")
Also, inkscape seems to add random translate transforms which don't make any sense. You'll need to parse and use those as well.

User avatar
flamingolady
Posts: 687
Joined: Wed Jun 10, 2009 1:40 pm

Re: Converting Coordinates in plane SVG File to Coordinates in Inkscape

Postby flamingolady » Fri Jul 14, 2017 7:44 am

EddieRich,
EddieRich wrote:The Width and height are defined by the page units times page scale (defined in the document properties dialog).
For instance, my page is 6 inches by 6 inches and my scale is 1000 "user units"
So, my viewbox is 0, 0, 6000, 6000.


In your example, how do you know that your scale is 1000 "user units"? Does that number change? From the very tiny bit that I can find on viewpoint, seems like it might. Is the user unit the pixels number of your page height? I have a similar issue as the OP (will need to export a font) using viewpoint (and have never used it).

dee

EddieRich
Posts: 5
Joined: Wed Jun 21, 2017 10:51 pm

Re: Converting Coordinates in plane SVG File to Coordinates in Inkscape

Postby EddieRich » Fri Jul 14, 2017 11:16 pm

flamingolady wrote:EddieRich,
In your example, how do you know that your scale is 1000 "user units"? Does that number change?
dee


I am using version 0.92, but it was the same in 0.91.
In the document properties dialog, page tab, under custom size, there is a scale section.
If you click the + next to the word viewbox, you can see/set the viewbox.
Normally, you would only set the X scale and Y will be the same.

I have found if you set the scale to high, the SVG paths start getting rounding errors.

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Converting Coordinates in plane SVG File to Coordinates in Inkscape

Postby Moini » Sat Jul 15, 2017 11:10 am

That part of the dialog is actually new in 0.92 and does not exist in 0.91.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)


Return to “SVG / XML Code”