isolining package for ActionScript 3

A week or so back I wrote about a package I ported/modified to create the Delaunay triangulation in Flash with a few AS3 classes. As I noted there, such a triangulated irregular network (TIN) allows us to interpolate isolines — lines of constant value (aka isarithms, commonly called contours).

So, given a field of points (weather stations, say)…

weather stations

…with one or more attributes attached (temperature, say)…

weather stations for interpolation

…a TIN can be constructed.

triangulated irregular network

With the above TIN, values can be interpolated along each edge between the points of known values (control points). The interpolation is strictly linear (that is, the value 50 would be interpolated halfway along an edge whose control points were valued 48 and 52).

interpolated points for isolining

With a given contouring interval (I’m using 4 degrees F here), we can connect some of these interpolated points, creating our contour lines.

rigid isolines, ready for smoothing

With the previous steps stripped away, this creates a passable isoline map.

masked isolines

The lines are rigid, though, and should be smoothed for presentation. I allow two methods for this. You can use the “simple” method, which just uses the built-in graphics method curveTo between the midpoint of each isoline segment (below with the isoline interval decreased to 3 degrees).

simple curves for isolining

The above looks alright, but the curves are not continuous, closed loops can still have hard corners, and the isolines no longer pass through the interpolated points (we have therefore generalized an already-inaccurate interpolation). My compatriot Andy Woodruff, author of the glorious new Cartogrammar blog, offered to write a nice continuous curve method that ensured isolines would still pass through the interpolated values. You can read about the method in his post. Here she blows:

continuous curves for isolining

Bringing it all together, then, and incorporating the only extra feature I wrote (tinting of isolines), here’s a nice finished isoline map of temperature across the U.S.

finished isoline map of U.S. temperature

My new isolining package for Flash/ActionScript3 accomplishes all of the above, requiring only an array of point data with attribute values attached. The above example, was accomplished with the following lines of code (after drawing the U.S. states from a shapefile).

//first, generate the array of triangles (ITriangle objects) from the point data
var triangles:Array = Delaunay.triangulate(points);
Delaunay.drawDelaunay(triangles, points, triClip, false); //comment this out if you don't want to draw the triangulation
//generate an array of isolines (isoline objects)
var isos:Array = IsoUtils.isoline(triangles, points, triClip, 3, 0);
//create color and class arrays for tinting the isolines
var classesArray:Array = new Array(40, 44, 48, 52, 56, 60, 64, 68, 72, 76);
var colorsArray:Array = new Array(0x051CFD, 0x4602FD, 0x6D0EEB, 0x8400FF, 0xC400FF, 0xEA00FF, 0xFF00E2, 0xFF0095, 0xFF0030, 0xFF0015, 0xFB3507);
//then, actually draw them, using a continuous curve
IsoUtils.drawIsolines(isos, triClip, "continuous", colorsArray, classesArray, .5, .95);

The full example is included in the .zip distribution. Get that here:

Keep in mind: triangulation is just one interpolation method, and is many ways the least technical (and accurate). More accurate interpolation techniques include inverse-distance and kriging. ***If you’re having trouble, and your isoline interval is not an integer, check out the comment at line 171 of isoUtils.as. Please fix that, BTW.

I meant to add other features, but since I started work this past week, I’m posting the package as-is, and invite others to modify. On my wishlist:

  • hypsometric tinting, or color between the lines, would allow for more effective terrain or temperature mapping
  • support for projections and other coordinate conversions in the drawIsolines method. I have packages for converting lat/long to a number of map projections, but currently the drawIsolines method doesn’t have support for passing a point coordinate conversion method.
  • an animated demo. This thing’s lightning-fast, so why not?
  • something that would be super wicked would be if someone would implement Tanaka’s illuminated contours [pdf] method, that thickens/thins and darkens/lightens lines like so…
    tanaka method
    …creating beautiful relief maps like the one below
    tanaka illuminated contours

If you add anything to the package, feel free to post a link to your revised version in the comments.

47 Comments

  1. Great stuff, thanks for taking the time to explain it as well as post it!

    Illuminated contours look lovely, I wonder if a passable version of them could be achieved with a BevelFilter?

    Posted June 9, 2008 at 2:18 am | Permalink
  2. AMAZING!

    grabring
    Posted July 28, 2008 at 11:11 am | Permalink
  3. ur api for contour is wonderful
    and thanks a lot to u
    i’d like to fill color between lines ,and want it bo be like
    http://blog.spatialkey.com/images/sacbee1.png

    how can i extend ur api?
    can u give me some hint?
    thanks a lot!

    aiya
    Posted September 2, 2008 at 1:20 am | Permalink
  4. this letter woman frog

    Posted September 17, 2008 at 11:08 am | Permalink
  5. The New Dress summary and study guide, with notes, essays, quotes, and pictures.

    Casino
    Posted September 17, 2008 at 1:56 pm | Permalink
  6. Get the latest mobile phones online at Dialaphone, the mobile phone shop offering great deals on the latest mobile phones.

    Posted September 17, 2008 at 1:56 pm | Permalink
  7. Hey, this is awesome… well done!!

    However for some reason the isolines mess up when the nodes/weather stations are square.

    It would be great if you could fix this.

    Raymond

    Posted January 15, 2009 at 11:51 am | Permalink
  8. This looks interesting. Iwas hoping to apply this to archaeological site densities…but not being all that computer savy I am not able to open the application files after unzipping. A little help please.

    erik
    Posted January 19, 2009 at 3:59 pm | Permalink
  9. @erik: Hello, this is a small library specifically for Flash, Flex, or ActionScript 3 projects. So if you want to display your data as an isoline on the web, it may be for you. But if you have no use for an ActionScript-specific solution, other options may be better for your needs. R & GRASS, for example, are free tools with lots of flexibility in contouring. Neither are very easy to get started with, but both would be easier to use (esp. importing your data) than my classes if you don’t need a Flash solution

    Posted January 20, 2009 at 6:54 pm | Permalink
  10. nice work you’ve done, congratulations! In our office we would like to generate our charts and diagramms esp. contour-maps with flash for interactive presentations. I’ve searched the web the last year and havn’t found the right stuff. I will try out your software, you are on the right way! The next weeks, I will also take a close look on alternative implementations for GIS-interpolations. For example: http://www.geog.ubc.ca/courses/geog470/notes/interpolation/interpolation.html
    when we can push your software into this… it would be a great deal! Thanx for your posting

    Kind regards

    Moritz

    Moritz Wagner
    Posted January 21, 2009 at 2:59 am | Permalink
  11. Not that I’m impressed a lot, but this is a lot more than I expected when I found a link on Delicious telling that the info here is quite decent. Thanks.

    Posted April 14, 2009 at 3:58 pm | Permalink
  12. система ниппель: туда суй - оттуда х#й

    Posted June 17, 2009 at 2:05 pm | Permalink
  13. Петербуржская Школа Правильного Питания (7 минут от метро “Чернышевская”) приглашает всех желающих избавиться от лишнего веса на бесплатные вечерние (18:45) ознакомительные занятия 15, 16, 18, 19 и 22 июня 2009г.
    Более подробная информация и запись на сайте - http://hudeem-vmeste.com

    ignikammipmep
    Posted June 17, 2009 at 7:53 pm | Permalink
  14. I have been looking for something like this for ages! It looks great.
    I just opened it up and I keep getting 8 of these compiler errors:
    Warning: 3596: Duplicate variable definition.

    Posted May 26, 2010 at 8:13 pm | Permalink
  15. 能给我一点资料吗?

    Posted May 28, 2010 at 10:04 am | Permalink
  16. Very impressive !. Congratulations and keep working as you do, your work is very useful !.

    Jose
    Posted May 29, 2010 at 5:10 pm | Permalink
  17. Hello All.
    I the first day here.
    It is assured to you it will be pleasant,news Blog

    http://keeley-hazellsex-tape.blogspot.com

    Posted July 8, 2010 at 4:22 am | Permalink
  18. well done! Your AS Libarary is most valuable.

    gisxxt
    Posted October 13, 2010 at 3:09 am | Permalink
  19. I think that if you give some examples such as organization of variable ‘points’ ,’triClip’, it will be easier to understand. However, your work is done very well, thanks for your share!

    gisxxt
    Posted October 13, 2010 at 3:15 am | Permalink
  20. Very nice your implementation for AS. Do you know something like this for PHP or JS?

    Thanks in advance

    Vinicius Cordeiro
    Posted August 24, 2011 at 8:53 pm | Permalink
  21. Aw, this was a very nice post. Finding the time and actual effort to create a very
    good article… but what can I say… I hesitate a lot and never seem to get nearly anything done.

    Posted June 1, 2013 at 8:30 pm | Permalink
  22. i want to know where to add the inputs. I am quite a noob in this matter.

    Satya
    Posted June 23, 2013 at 9:53 am | Permalink
  23. Hi there, I found your website by means of Google even as looking for a comparable subject, your site got here up,
    it appears great. I have bookmarked it in my google bookmarks.

    Hi there, just turned into aware of your weblog through
    Google, and located that it is really informative. I am going to
    watch out for brussels. I will be grateful in the event you continue this in future.
    Numerous other people will probably be benefited from your writing.
    Cheers!

    Posted September 22, 2013 at 8:45 am | Permalink
  24. Asking questions are genuinely fastidious thing if you are
    not understanding anything fully, however this post offers nice understanding yet.

    Posted March 1, 2014 at 7:36 pm | Permalink
  25. Hey there! I simply wosh to offer you a huge tyumbs
    up for the excellent info youu have got right here
    on this post. I will be coming back to your web
    site for more soon.

    Posted April 13, 2014 at 7:22 pm | Permalink
  26. I am really glad to read this webpage posts which consists oof tons of useful facts,
    thanks for providing such information.

    Posted April 18, 2014 at 8:53 am | Permalink
  27. have you finished “hypsometric tinting”?

    monica
    Posted April 21, 2014 at 2:43 am | Permalink
  28. @zach’ry:Hello,have you finished “hypsometric tinting”?

    monica
    Posted May 5, 2014 at 3:06 am | Permalink
  29. @zach’ry:Hello,have you finished doing “hypsometric tinting”?

    monica
    Posted May 5, 2014 at 3:07 am | Permalink
  30. Jе suis entièrement en accord avec toi

    Posted May 12, 2014 at 12:49 pm | Permalink
  31. Vraiment attrayant : mon petit doigt me dit que ce post intéresserait ma gonzesse

    Posted June 5, 2014 at 1:09 pm | Permalink
  32. On peut te dire que ce n’est nullement erroné !!!

    Posted June 5, 2014 at 2:46 pm | Permalink
  33. Je me permets d’écrire ce commentaire uniquement pour complimenter
    son auteur

    Posted June 6, 2014 at 3:08 am | Permalink
  34. Tiens ce post va atterrir sur mon site

    Posted June 6, 2014 at 1:10 pm | Permalink
  35. C’est infiniment un bonheur de venir sur ce site web

    Elwood
    Posted July 14, 2014 at 10:47 am | Permalink
  36. Please let me know if you’re looking for a author for your weblog.
    You have some really good articles and I believe I would be a good asset.

    If you ever want to take some of the load off, I’d really like to write some
    content for your blog in exchange for a link back to mine.
    Please blast me an email if interested. Regards!

    Posted December 13, 2014 at 3:25 pm | Permalink
  37. I could stay with him. Since I left I was disowned by my dad beausce I wasn’t into religion as he is and for a couple other reasons that aren’t really necessary, but I had a terrible childhood with him anyways. My mom; out of the picture. Things started going terrible with my uncle, tried to get me into hard drugs as he was, as well as something else and I ended up leaving their immediately and since then I was on the streets and I pretty much just gave up.I know that’s a pretty sad excuse..It was for about a month and almost 3 weeks. I was walking off the skytrain and this guy walked by me and looked at me funny and it was definitely hard to miss..I didn’t think much of it, but then about 20 seconds later he walked back and said he’s seen me around a few times and asked if I wanted to go get something to eat with him and I said sure. We went to subway and he got me something and we started talking and he immediately asked me what happened? as he knew I was homeless I guess and I explained to him. We talked a lot and he asked me If I was Romanian..Its in my background so he was right and I asked why and he said you just look it as I am too, but we both don’t speak it.Basically we went around and talked for a few hours after eating and he was really interesting and he seemed REALLY interested in me which I thought was extremely strange, he looked wealthy and extremely physically attractive. He brought me to his apartment and before I went in I asked if he was a pimp beausce I’ve been approached a couple other times and completely avoided it, and he laughed and said no I’m not and pulled out his ID and it showed he was 17, so he was almost 5 years younger then me, I thought he was AT LEAST 25, absolutely no way I thought he could have been 17 by the way he was developed and how he carried himself ..We went in and he lived alone, nicely set up but of course not a new apartment but it was still nice, and he said you can stay here, its safer for you then being outside, and I didn’t really know what to say and he insisted saying its really okay..I just of course felt a little bad but I said okay. He trusted me completely, set up blankets on the couch for me to sleep and said you can stay here as long as you want. I asked him why are you doing this for me and he told me I just see something special in you ..I’ve been here for 12 days now, he insisted buying me clothes and some stuff I needed, he even went out with me to help me find a job, and I start working on Saturday..Everyday he takes me out and we go eat and spend all his free time with me, he even got my a gym pass and he takes me to the gym every night and we go swimming after..I’m 5′3 about 105lbs but I’d like to gain a bit of muscle so he shows me a lot which is really cool.. we talk about everything and I asked why he is living alone and he explained he had a bad and abusive childhood and has been on his own since 15, his older brother is in jail for murdering his mother and his dad is dead too, and that he has NO family. He works from 9 to 4, he works for the city and told me he met someone who was a senior who is a manager for the city or something and hired him beausce of his situation, and he literally works his butt off to keep it beausce of the pay and the benefits, and after we go right to the gym to work out, and then when we get back he does a bit of schooling online for a couple hours that he lets me help him with a bit too.Even though I’ve known him for 12 days or so, we just get a long so well and I didn’t expect anything like this to ever happen. I’m just confused in a way why he’s interested in me, not trying to brag or anything but I can see him being with some high maintnence blonde barbie doll girl with fake breasts or any girl he wants really :S I have shorter brown hair and Ive never even been one to wear makeup I just dont like to.. he’s such a hard working person and responsible for his age, doesn’t seem to have many friends though but he says he has a couple close ones but thats about it..Is he interested in me in a relationship way? I just don’t know..He always looks in my eyes when he talks to me though, so I guess that can be a hint..We watch movies at night but we don’t cuddle or anything and I’d really like to honestly but we do sit close, how can I bring it up, or if I just rested my head on his shoulder, would it be a bad idea? I still sleep on the couch, how would he react if I went into his room at night and asked if I could sleep with him just so we can cuddle or give affection? I don’t want him to think the wrongidea, beausce I’m NOT that kind of girl we both had bad childhoods and we can relate a lot about lots of things, we both dont do drugs either and about the age, it doesnt matter to me at all..We’re in Canada as well so nothing is illegal. I’m just wondering if he is looking for a relationship or not, and if it would be a good idea if I made a move as in asking to cuddle or anything like that, I just don’t want things to get awkward but honestly I know he’s really comfortable with me and I’m comfortable with him as well as we talk just about everything together, there isn’t anything we’re not comfortable talking about and we joke around a lot as well. He explained that I can live with him for as long as you want and never to be afraid of asking for anything beausce he’ll help me no matter what and that he knows how it feels to be homeless and how hard it can be. For example he works lots and then at the gym real hard afterwards and I can tell he’sreally exhausted when we get home..what if I offered to give him a massage oranything like that? I just want to know if it would be a good idea or not to ask him if he would like me to give him any affection at all, beausce I know he’s never really receieved any when he was younger..as I didn’t really eitherand oh for example when we go swimming we play around and stuff and we’ve touched eachother’s body but not sexually of course, but in the pool..and for the last 4 days or so we sit on the couch together oppose to sitting on opposite couches little things like that.I also told him when I start working I’m going to be helping with rent and utilities, I could honestly say we trust each other 100% even if it’s that fast..And he accepted that I will help pay and he is fine with that.

    Posted January 9, 2015 at 4:37 pm | Permalink
  38. I love what you guys are usually up too.
    This kind of clever work and exposure! Keep up the fantastic works guys I’ve added youu guys to my own blogroll.

    Posted January 21, 2015 at 1:44 pm | Permalink
  39. Great beat ! I wish to apprentice while you amend your site, how can i subscribe for a blog site?
    The account helped me a acceptable deal. I had
    been a little bit acquainted of this your broadcast offered bright
    clear concept

    Posted March 17, 2015 at 10:02 pm | Permalink
  40. Utomordentligt roande förhållningssätt! Jag avgudar föreställningen /x

    Posted March 27, 2015 at 10:59 am | Permalink
  41. Hi there colleagues, its impressive article on the topic of cultureand completely explained,
    keep it up all the time.

    Posted March 30, 2015 at 7:13 pm | Permalink
  42. It’s a pleasure to find someone who can identify the issues so clearly

    Posted March 30, 2015 at 9:22 pm | Permalink
  43. Sandy,I think that the word “post” refers to anything written that is “posted” online. That post may have all the characteristics of an article, and could be accurately labeled as such. The difference being that print media would never call an article a post, whereas online media might use either word.Lewis, bizsolutionsplus

    Posted March 30, 2015 at 9:23 pm | Permalink
  44. I encourage you to make a resolve for excellence which means that your finished product represents the Lord in a very worthy fashion. This as Enrique Parrilla says, ‘instills a feeling of urgency’ to back
    a project as there is still the opportunity invest in it.
    Nothing to several hundred dollars or more depending on what you want to do yourself or what
    you want help with.

    Posted April 10, 2015 at 2:52 am | Permalink
  45. , She Said Should He Leave?He Said:Should I leave my wife?We’ve been married for 34 years. I haven’t loved her for searvel years and haven’t had sex for nearly that long. It hurts her back. There isn’t even any affection which I seem to thrive on. I also feel there is a big communication problem because when I say something, she responds with something entirely different. She seems to have selective memory and forgets almost everything I tell her.I haven’t been looking for someone else, but when I met someone that I connect with it seems so right. Recently my wife found out about my 3rd affair. Although she was mad and hurt, she has gotten to a point where she will not deal with it. I obviously had affairs for a reason. I don’t really want to leave my marriage, but I can’t stand to remain unhappy and unfulfulled like this. We have gone to marriage couseling in the past and it lasted for awhile, but then she would forget what we learned. I haven’t had fun with her in quite some time. Most of the time I think she has her head in the sand and thinks that everything will be ok. My children are grown and one supports me that I should go where I’m the happiest. My daughter wants to give it one more try and if it doesn’t work out, then leave. The thought of ended my affair is very difficult to accept. She and I seem like we’re made for each other. But I know if I divorce my wife, it will be so final.Before you respond to this question, I want to point something out that I have noticed about women men’s response to infidelity. If its a guy cheating they jump all over him and condem him. If its a girl that cheats, they somehow seem to look at it much more rationally ..WTH? Please try to put yourself in my shoes and tell me what you think I should do.•19 hours ago•- 1 week left to answer.Additional Details8 hours agoSome of you have ask about my contribution to this marriage over the years. Since I am a Cancer, I naturally nurture, love, protect and take care of her. Since she is on fixed income and cannot work, my job as the sole provider has been stressful at times. But I want to point out that if/when I leave I will be taking all of the bills with me. During this entire time, I have taken care of her when she has shoulder aches or migraines ..she’s not confined, she just can’t sit for very long. I would do the dishes, get her something to eat, go to the store for her .stuff like that. I’m always looked out for her best interest and tried to make her comfortable. Basically sacrificing my needs for hers. Sounds similar to what women do for men doesn’t it. She in turn, has been right there for me during my illnesses. I’ve had 6 major surgeries since 2004 and she has been right by my side the entire time.You guys are awesome and your answers really help me out. thanks, steveShe Said:Should Steve Leave His Wife?Steve posted the question, should he leave his wife?I’m the other woman in this scenario and would like to add my perspective:While he was in the hospital this last time, I could not be with him as I’m an interstate driver and was out of state. I was in anguish about not being there and only survived by staying in phone contact with him and the hospital. When he called me one day, I was horrified to learn that he was sick from medications and complications, and his wife would not question the staff on his behalf, for fear of causing trouble, believing they knew what they were doing. In truth, it turned out, things were going on that caused him to have to receive two more surgeries after the initial one. When he told me she would not intervene, I got on the phone with the hospital staff and would not relent until answers were given and solutions were being sought. I made many phone calls during that time, from the nurse, to the head nurse, to the director of nursing, to the surgeon, in order to get things done. So, while she was there everyday, as Steve said, she would not stand up for him or behind him when he needed her. When I did get within travelling distance and had a weekend to spare, I rented a car and drove 500 miles each way to visit him.Steve did not say in his posting that he has moral convictions that are making this very difficult for him; I understand that and we’re dealing with that together. I don’t want to be a home-wrecker and never sought out a married man. He is not in love with his wife. We have an uncommon bond that’s being built day by day on friendship and mutual respect. I would uproot my life to be with this man, but not until and if he’s ever ready to make the life change. I’m not pushing him because I want him to be sure and have no regrets. He’s soul-searching and so am I. If he decides he cannot be with me, I’ll accept it and disappear. But he’s not happy now and we’re both very, very happy when we’re together. I want, more than anything, for him to be happy, even if that happiness is not with me. Ellie what a thoughtful, insightful message. Thank you for that.In fact, we have discussed at length what we would need to do if he did decide to leave, these matters concerning his wife. I do sympathize with her, believe it or not, and would be more than willing to help. Steve knows this.

    Tracy
    Posted April 11, 2015 at 8:55 pm | Permalink
  46. fantastic put up, very informative. I’m wondering why the opposite experts of
    this sector do not realize this. You should proceed your
    writing. I’m sure, you have a great readers’ base already!

    Posted May 25, 2015 at 2:36 am | Permalink
  47. Can you please elaborate what you want to share?

    Posted July 7, 2015 at 2:38 am | Permalink

8 Trackbacks

  1. [...] isolining package for ActionScript 3 You can use the “simple” method, which just uses the built-in graphics method curveTo between the midpoint of each isoline segment (below with the isoline interval decreased to 3 degrees). The above looks alright, but the curves are not … [...]

  2. [...] update: for a cool usage of Delaunay triangulation, see my isolining package for ActionScript 3 [...]

  3. By The Kraken - A Software Development Journal on February 15, 2011 at 1:14 am

    [...] specially aggregated data-structure into isoLines input Posted: February 15th, 2011 Categories: OOP Tags: Comments: No Comments. Write a comment [...]

  4. [...] your browser interpolate isolines is fun! I first did these in ActionScript 3 back in 2008. This JavaScript version works essentially the same way: generating a triangulated irregular [...]

  5. [...] uses these triangulations in his map-making, you’ve gotta check out the sequence of images on this page. It’s incredible how just a scattering of local temperature measurements can be extended to [...]

  6. [...] 原文:isolining package for ActionScript 3 [...]

  7. By 等值线算法-网站收藏 on May 21, 2013 at 10:17 pm

    [...] as版等值线 http://indiemaps.com/blog/2008/06/isolining-package-for-actionscript-3/ geoserver拓展的等值线 [...]

  8. [...] colorful contour lines that arise from the differential equation governing heat flow. The temperature maps by Zachary Forest Johnson from a few weeks ago also used contour lines. And I found some great [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *