Results 1 to 10 of 23

Thread: Weighted Centroidal Voronoi Stippling using JTS

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Redrobes's Avatar
    Join Date
    Dec 2007
    Location
    England
    Posts
    7,201
    Blog Entries
    8

    Default

    You can do that in three lines of perl or sed using a regular expressions (and one of those was just to add extra spaces after the commas). If this is the sort of thing you are doing then you should ensure your well familiar with them cos it makes manipulation like this so easy.

    Code:
    $in = '<path d="M 258.59905,189.69191 80.812204,365.45845 264.65997,692.74788 220.21325,510.92042 519.21841,434.14883 385.87827,246.26045 z" />';
    $out = $in;
    
    $out =~ s/<path d="M /LINESTRING (/;
    $out =~ s/ z" \/>/)/;
    $out =~ s/,/, /g;
    
    print "Before: $in\n";
    print "After : $out\n";
    
    
    
    # Results:
    #
    # Before: <path d="M 258.59905,189.69191 80.812204,365.45845 264.65997,692.74788 220.21325,510.92042 519.21841,434.14883 385.87827,246.26045 z" />
    # After : LINESTRING (258.59905, 189.69191 80.812204, 365.45845 264.65997, 692.74788 220.21325, 510.92042 519.21841, 434.14883 385.87827, 246.26045)
    #

  2. #2
    Software Dev/Rep Hai-Etlik's Avatar
    Join Date
    May 2009
    Location
    48° 28′ N 123° 8′ W
    Posts
    1,333
    Blog Entries
    1

    Default

    That might work in this very specific case, but not for SVG Path Data in general. Like I said, SVG is flexible and allows a lot of different ways of expressing things. Dealing with all those different ways is the hard part. You can express numbers as integers, decimals, or in scientific notiation, you can use commas or spaces as separators, commands and numbers don't need to be separated, but can be, commands can be omitted in which case you repeat the previous one with the next set of parameters, unless it was a moveto command in which case you treat the repetitions as lineto commands. Closed paths are handled differently between the two requiring that you keep track of the first point of any subpath, and just about every command has a relative form requiring you keep track of the most recent point as well.

    And that's not even getting into the problem of all the curved path sections like bezier curves and elliptic arcs.

    PS:
    That said, I am using Regexps, it just takes a fair bit beyond regexps. Also, I wanted to be able to load directly into JTS; the WKT export is just corollary of sorts since JTS already has WKT export. Ultimately I'd be aiming to use the Centroidal Voronoi algorithm from the start of the thread on shapes loaded from an SVG file.

    PPS: The topological issues with turning closed SVG paths into JTS Polygons or Multipolygons is going to be a lot of work too. SVG allows subpaths to intersect themselves and each other, and doesn't make topological distinctions between them. The The OGC Simple Features data model used by JTS doesn't allow intersecting rings, and does make a distinction between a polygons with an enclave, and a multipolygon with an exclave.
    Last edited by Hai-Etlik; 06-29-2011 at 05:57 PM.

  3. #3

    Default

    Lordy, I remember just barely touching on some things similar to these issues way back when in earlier software, and all the headaches it caused.

    Good luck, and you have my sympathies!
    My Finished Maps | My Planet Maps | My Challenge Entries | Album: Pre-generated Worlds

    ------
    Assuming I stick with fantasy cartography, I'd like to become a World Builder, laying out not only a realistic topography, but also the geopolitical boundaries and at least rough descriptions of the countries and societies.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •